Android:使用xmlwise在res/raw中找不到plist [英] Android: Cannot find plist in res/raw using xmlwise
本文介绍了Android:使用xmlwise在res/raw中找不到plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用xml智慧将plist读取到我的android应用中.这是我的代码
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);
但我不断得到:
java.io.FileNotFoundException: /android.resource:/com.packagename.appname/2130968577 (No such file or directory)
在我的res/raw
文件夹中获取我的plist nameofplist.plist
路径的正确方法是什么?
What is the proper way to get the path to my plist nameofplist.plist
in my res/raw
folder?
推荐答案
我也很难为这个问题找到答案...但最终我找到了答案.
I struggled to find an answer to this too... but I worked it out eventually.
这是我的解决方案,它基于位于res/raw文件夹中的名为 airports.plist 的plist文件.
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();
}
希望这对某人有帮助!
这篇关于Android:使用xmlwise在res/raw中找不到plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文