Android的路径资产txt文件路径、资产、文件、Android

2023-09-12 00:37:07 作者:尐纞筁

我做的:

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

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

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

解决方案

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

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

怎样把DOC文件转换成TXT文件

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.