Android的路径资产txt文件 [英] Android path to asset txt file

查看:152
本文介绍了Android的路径资产txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的:

的FileReader鳍=新的FileReader(文件:///android_asset/myFile.txt);

在一个Android项目,许多变化。在运行时,我得到未发现异常文件。该文件是present,正确的资产文件夹,所以我的路径必须是错误的。

什么是绝对路径,我需要在这里?

解决方案

  AssetFileDescriptor描述符= getAssets()openFd(myfile.txt的)。
的FileReader读卡器=新的FileReader(descriptor.getFileDescriptor());
 

尝试使用上面FileDescriptors。似乎是最万无一失的方法,我发现收集的资产的路径。

I'm doing:

FileReader fin = new FileReader("file:///android_asset/myFile.txt");

in an Android project and many variations. At runtime I get a file not found exception. The file is present and correct in the assets folder, so my path must be wrong.

What is the absolute path I need here?

解决方案

AssetFileDescriptor descriptor = getAssets().openFd("myfile.txt");
FileReader reader = new FileReader(descriptor.getFileDescriptor());

Try using the above with FileDescriptors. Seems to be the most foolproof way I've found to gather asset paths.

这篇关于Android的路径资产txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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