I'm reading in data from a file which is "packed" (each two values packed into one bit). I can view this data with an unpack utility to verify that it is correct. However, when I bring it in to my Java app, it reads two characters in wrong.. ie: reads both 24 and 85 in as 45.
My method of reading in from the file is using BufferedReader.readLine() into a String variable and then using String.getBytes() to then begin parsing the string to "unpack" it.
As stated, it works in all cases except two values.
In an attempt to get a unique value for each so I can individually parse them, I have tried to out to the command line things like the ASCII value, Integer.decode, and String.hashCode... but they all seem to be read in as identicle values even though I have proven they are not identicle in my other viewer.
Any suggestions as to tests to try against the two in order to prove them not equal are appreciated and will be attempted.
If using BufferedReader into a string then getBytes is my problem, I will attempt to change it to your suggestion.
All "Readers" expect to work with valid character data, and will do some translation in a platform- and character-set-dependent way. It sounds like you don't have character data at all, but encoded data, which you have to treat as raw binary. InputStreams, as opposed to Readers, will never modify the data stream for you. That's what you want.
So use a FileInputStream to read the data; don't try to read a line at a time, just read into a byte. Create a decoded byte yourself, and then you can use the appropriate String constructor to turn the decoded data into a String.
Thank you very much Ernest. Changing my input from BufferedReader to FileInputStream has given me the proper results! Now I'm trying to move my application to use the FIS instead of the BR which is proving to be a little more quirky than just changing class names, but it's coming along nicely.
Thank you for your help!
Joined: Dec 19, 2001
Originally I was still doing my Buffered Read into a string to get the length of a single line and create a byte array of the appropriate length of that line.
But I expect there must be an easier/more efficient way.. suggestions?