This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes File conversion - going wacky ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "File conversion - going wacky !" Watch "File conversion - going wacky !" New topic

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) {
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..



Regards, Dave Brown
SCJP 6 - [url][/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 the questionable byte is read in ok.

When i'm reading the bytes using; 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.
I agree. Here's the link:
subject: File conversion - going wacky !
It's not a secret anymore!