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

时间:2013-03-02 23:54:03

标签: android xml-parsing plist

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

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

但我一直在接受:

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

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

1 个答案:

答案 0 :(得分:9)

我也在努力寻找答案......但我最终还是把它解决了。

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

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();
}

希望这有助于某人!