2010-08-10 61 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);