This is my 1st post so please be gentle
I'm currently trying to read in a raw text file of ints in an android application and running into all sorts of issues. Currently I have the code -
This works great, except that it reads the the ascii code of the int instead of the value, eg. 2 in my file turns into 50. I've tried different ways of reading the file such as using dataInputStreams and bufferedInputSteeams but these don't seem to compile at all so I think I'm barking up the wrong tree with that approach. As far as I can see I have 2 options, store the ints in a different format like a database (seems like overkill), convert the ascii codes to there represented values in some way (should work if I knew how).
Does anyone have any ideas? I've chased my tail all over the net with this one.
The InputStream.read() method reads a single byte. If you created a text file with a "2" in the first position, that "2" is an ASCII character, and "2" in ASCII is really 0x32 in hex, and 0x32 in hex is 50 as an integer.
If you want to read ASCII (or UTF-8) characters out of a file you must use a text input method, not a binary input method. Try the Reader.read() methods or BufferedReader.readline().