Android: Cannot find plist in res/raw using xmlwise

一曲冷凌霜 提交于 2019-12-25 03:35:06

问题


I am trying to read a plist into my android app using xml wise. This is my code

String path = "android.resource://" + context.getPackageName() + "/" + R.raw.nameofplist;
Map<String, Object> males = Plist.load(path);

But i keep getting:

java.io.FileNotFoundException: /android.resource:/com.packagename.appname/2130968577 (No such file or directory)

What is the proper way to get the path to my plist nameofplist.plist in my res/raw folder?


回答1:


I struggled to find an answer to this too... but I worked it out eventually.

Here's my solution based on a plist file called airports.plist sitting in the res/raw folder.

Map<String, Object> properties = null;
try {
    InputStream inputStream =getResources().openRawResource(R.raw.airports);
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(inputStream));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        properties = Plist.fromXml(sb.toString());

        //TODO do something with the object here
        System.out.println("plist object... "+properties);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        br.close();
    }
} catch (Exception ex) {
    ex.printStackTrace();
}

Hope this helps someone!



来源:https://stackoverflow.com/questions/15180821/android-cannot-find-plist-in-res-raw-using-xmlwise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!