| Author |
File conversion - going wacky !
|
Dave Brown
Ranch Hand
Joined: Mar 08, 2005
Posts: 301
|
|
Hi All, I have a bunch of files I need to process, So far I thought the program i wrote was working correctly until I noticed that the chars I am reading & processing are not reflecting the true chars in the file. For example.. My program gets to a certain point in the file which I know the byte on file is 0xD2.. Instead of D2 I get 3F. I am doing a little test here if (cnt == 284) { test.write((char)buffer[i]); System.out.println("buffer = " + Integer.toString (buffer[i],16)); } Just to see what the hex equiv of what it thinks its reading is, and the output is actually "-2e" minus the quotes. I am reading the file in straight into a buffer using FileInputStream. If anyone could shed some light on this that would be great, its bugging the hell out of me.. THanks, Dave.
|
Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
|
 |
Dave Brown
Ranch Hand
Joined: Mar 08, 2005
Posts: 301
|
|
If this helps... When reading one byte at time using in.read() the questionable byte is read in ok. When i'm reading the bytes using in.read(buffer); the byte is changed, could the fileinputstream be doing some encoding ?
|
 |
Dave Brown
Ranch Hand
Joined: Mar 08, 2005
Posts: 301
|
|
It appears the problem was to do with the way I was outputting data.. Using OuptputStreamWriter and chars.. when I switched to bytes and FileOutputStream, everything worked.
|
 |
 |
|
|
subject: File conversion - going wacky !
|
|
|