Android:使用xmlwise无法在res/raw中找到plist

Mat*_*Hui 0 android plist xml-parsing

我正在尝试使用xml明智地将plist读入我的Android应用程序.这是我的代码

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

但我一直得到:

java.io.FileNotFoundException: /android.resource:/com.packagename.appname/2130968577 (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

nameofplist.plist在我的res/raw文件夹中获取我的plist路径的正确方法是什么?

gts*_*101 9

我也很努力地找到答案......但最终我解决了这个问题.

这是我的解决方案,它基于名为airports.plist的plist文件,位于res/raw文件夹中.

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();
}
Run Code Online (Sandbox Code Playgroud)

希望这有助于某人!