2014-09-05 77 views
-1

如何使用函数从assets文件夹中获取XML文件并将函数的结果保存到String变量中?如何使用函数从资产文件夹中获取XML文件?

+0

那你尝试和具体是什么问题呢? – laalto 2014-09-05 07:56:19

+0

你的应用程序有什么问题? – 2014-09-05 07:58:38

+0

我尝试使用androidhive;解析地址中的xml文件的示例。但是,我需要解析位于我的资产文件夹下的xml文件。你可以参考这个链接。 http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/ – user2992771 2014-09-05 08:00:32

回答

0
private String getXmlFile(String pathFile){ 

    String xmlFileString = null; 
    AssetManager am = context.getAssets(); 
    try { 
    InputStream str = am.open(pathFile); 
    int length = str.available(); 
    byte[] data = new byte[length]; 
    //str.what you want somthing to do...eg read and write str.read(data); and st.write(data); 
    xmlFileString = new String(data); 
     } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 

    return xmlFileString; 
    } 
0

帮助完整。在V

AssetManager assetManager = getBaseContext()getAssets()。

InputStream is = assetManager.open(“order.xml”);

Xml Parsing From Asset in Android

相关问题