安卓:getAssets().openFd() 和 FileNotFoundException

标签 android android-assets

我正在尝试从 assets 文件夹中读取一个 txt 文件:

descriptor = context.getAssets().openFd("openAccess.txt");
reader = new FileReader(descriptor.getFileDescriptor());

但我遇到了这个异常:

java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

不知道是什么问题?

最佳答案

这个怎么样:

InputStream in = context.getAssets().open("openAccess.txt");
reader = new InputStreamReader(in);

关于安卓:getAssets().openFd() 和 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10141251/

相关文章:

java - 使用 Assets 从android中的文件中读取

android - 如何为 VideoView.setVideoURI() 中的参数获取 Assets 中文件的 Uri

android - Gradle 同步失败 : ERROR: Expected ':' at line 1 column 11 path $. 请

android - SERVICE_VERSION_UPDATE_REQUIRED 和 Google play 服务在 android 中集成 Google Plus 时已过时

java - 如何获得有关我的应用程序中发生的异常的更多详细信息?

java - 使用 Netty 提供文件 - 响应被截断一个字节

javascript - Android从asset文件夹加载加密的HTML+JS到webview

android - 从 xml 文件 android 中的 Assets 文件夹定义字体

android - 增强现实

Android FlexboxLayout : android:animateLayoutChanges not working when child view resized