Android的:getAssets()openFd()和FileNotFoundException异常 [英] Android: getAssets().openFd() and FileNotFoundException

查看:5875
本文介绍了Android的:getAssets()openFd()和FileNotFoundException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读一个txt文件,从文件夹中的资产这样的:

I am trying to read a txt file from assets folder like that:

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

但我得到这个异​​常:

but I am getting this exception:

java.io.FileNotFoundException:此文件无法打开作为一个文件
  描述;它可能是COM pressed

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

我不知道是什么问题?

推荐答案

试试这个:

AssetFileDescriptor descriptor = getAssets().openFd("openAccess.txt");
BufferedReader f = new BufferedReader(new FileReader(descriptor.getFileDescriptor()));
String line = f.readLine();
while (line != null) {
    // do stuff
    Log.d("TAG",line);
}

这篇关于Android的:getAssets()openFd()和FileNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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