this'll be my first post on SO so please be gentle. I'm currently developing an Android app and am attempting to simply read a .txt file in. After many seperate hurdles to overcome (this is my first attempt at reading in a text file) I've come across a rather nasty problem of it throwing the error message
This file cannot be opened as a file descriptor; it is probably compressed.
assetmgr = thiscontext.getAssets();
try {
descriptor = assetmgr.openFd("level1.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The above piece of code is simply attempting to read in the text file. However, it is returning null to descriptor which is obviously causing errors further down the line.
inputStream = new FileReader(descriptor.getFileDescriptor());
This is the line that is initialising the inputstream for parsing the text file in the loop I've created out of this scope.
So my problem is how do I fix the txt file not opening correctly and apprarently being compressed.
If I have made any errors in posting please let me know so I can correct them to get the best possible advice!
Cheers!
So my problem is how do I fix the txt file not opening correctly and apprarently being compressed.
Instead of calling openFd()
, call open()
, to get an InputStream
directly, and replace your FileReader
with an InputStreamReader
(if you really want a Reader
interface).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With