Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File conversion - going wacky !

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic