Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: getAssets().openFd() and FileNotFoundException

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

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

but I am getting this exception:

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

I don't know what is the problem?

like image 652
Milos Cuculovic Avatar asked Apr 13 '12 12:04

Milos Cuculovic


2 Answers

How about this:

InputStream in = context.getAssets().open("openAccess.txt");
reader = new InputStreamReader(in);
like image 193
David Wasser Avatar answered Sep 21 '22 17:09

David Wasser


try this :

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);
}
like image 44
ρяσѕρєя K Avatar answered Sep 19 '22 17:09

ρяσѕρєя K