介绍两种Android开发中获取xml文件的输入流对象

第一种:通过assets目录获取

1.首先是在Project下app/src/main目录下创建一个assets文件夹,将需要获取的xml文件放进去

2.在代码中获取AssetManager

AssetManager am = this.getAssets();

3.调用AssetManager的open方法即可获取到对应xml的流对象

InputStream is = am.open("weather.xml");

第二种:通过raw目录获取

1.在res下创建一个raw文件夹,将需要获取的xml文件放进去

2.在Activity中通过如下代码获取输入流对象

InputStream is = getResources().openRawResource(R.raw.weather);

 

相关文章:

  • 2021-07-23
  • 2021-11-05
  • 2021-07-02
  • 2021-11-10
  • 2021-09-06
  • 2022-12-23
猜你喜欢
  • 2021-05-01
  • 2022-12-23
  • 2021-06-09
  • 2022-01-14
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案