使用文件路径为XML从资产的Andr​​oid文件夹 [英] Using filePath for an xml from assets folder in Android

查看:177
本文介绍了使用文件路径为XML从资产的Andr​​oid文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用存在于Android的资产文件夹,像这样的XML文件的文件路径:

I am trying to use the filepath of an xml file that exists in the assets folder of android, like this:

String filename = "file:///android_asset/test.xml";
FileInputStream fis =  new FileInputStream(new File(filename));

的System.out.println(的FileInputStream:+ FIS); //此处失败
我得到一个

System.out.println("FileInputStream : " + fis); // here it fails I get an

java.io.FileNotFoundException:/file:/android_asset/text.xml

java.io.FileNotFoundException: /file:/android_asset/text.xml

错误,它没有任何意义,我。

error and it does not make sense to me.

我做了APK和总指挥官打开它,然后和XML是在资产的文件夹中。你看到我的方法有问题?谢谢你。

I made an apk and opened it then with total commander and the xml is in the assets folder. Do you see a problem in my approach? Thank you.

推荐答案

刚刚获得的InputStream,

Just get the InputStream,

InputStream is = getApplicationContext().getAssets().open("test.xml");

您还可以保持在 RES / XML 文件夹中的XML,只是得到它

You can also keep your xml in the res/xml folder and just get it working by

getResources().getXml(R.xml.test);

在这里 是相同的一个完整的例子。

Here is a complete example for the same.

这篇关于使用文件路径为XML从资产的Andr​​oid文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆