我怎样才能解析位于系统我的本地XML文件的硬盘?
How can I parse my local XML file located in the systems hard disk?
如果您的文件位于/ SD卡目录,你可以使用
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");
之后,你可以使用DOM和SAX做你的XML解析
After that you can use DOM or SAX to do your XML parsing
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
上一篇:如何打开默认浏览器浏览器