Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse binary file (word16 format) and convert to short

Status
Not open for further replies.

EBMer

Programmer
Nov 4, 2003
1
DE
binary files:
word16 format; Byte order is little endian; they stor short values

Now I want to parse these files, getting the short values and write them in ASCII format to a new file, using Java's New IO. I made a channel and a buffer:

FileChannel fcOut = new FileInputStream(file).getChannel();
ByteBuffer buff = fcOut.map(FileChannel.MapMode.READ_ONLY, 0,fcOut.size());
...

but I have no clue how to convert the input. I tried a lot, but I always get much too much output (the file size extended 10 times the size of the original file).
I believe it must be really easy, but, as I'm rather new to OOP/Java, I have no idea. Any suggestions?
 
You should be able to let java convert the stream.

FileInputStream fin = new FileInputStream(file);
Reader reader = new InputStreamReader(fin, "UTF-16LE");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top