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

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

问题描述

我在做:

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

在一个 Android 项目和许多变体中.在运行时,我收到一个文件未找到异常.该文件在assets文件夹中存在且正确,所以我的路径一定是错误的.

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());

尝试将上述内容与 FileDescriptors 结合使用.似乎是我发现的收集资产路径的最简单的方法.

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

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

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