Reputation: 11
How can I parse my local XML file located in the systems hard disk?
Upvotes: 1
Views: 1247
Reputation: 24472
If your file is located in the /sdcard dir, you can use
InputStream in = new FileInputStream("/sdcard/myfile.xml");
If its located in your app's data directory, you can use
File f1=new File(context.getFilesDir(), "myfile.xml");
InputStream in = new FileInputStream(f1);
If its located inside your assets/ directory, you can use:
AssetManager assets = context.getAssets();
InputStream in = assets.open("myfile.xml");
After that you can use DOM or SAX to do your XML parsing
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
Upvotes: 4