Android: getAssets().openFd() and FileNotFoundException

Miloš picture Miloš · Apr 13, 2012 · Viewed 18.4k times · Source

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?

Answer

David Wasser picture David Wasser · Apr 13, 2012

How about this:

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