Reputation: 3361
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?
Upvotes: 0
Views: 1046
Reputation: 729
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!
Upvotes: 9