2010-08-10 58 views

回答

4

如果您的文件位于/ SD卡目录,你可以使用

InputStream in = new FileInputStream("/sdcard/myfile.xml"); 

如果它位于你的应用程序的数据目录,你可以使用

File f1=new File(context.getFilesDir(), "myfile.xml"); 
InputStream in = new FileInputStream(f1); 

如果它位于你的资产内/目录,你可以使用:

AssetManager assets = context.getAssets(); 
InputStream in = assets.open("myfile.xml"); 

之后,你可以使用DOM或SAX来做你的XML解析

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
Document doc = builder.parse(in);