View Single Post
  #2 (permalink)  
Old 08-07-2007, 07:06 AM
coco coco is offline
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
How exactly are you reading the data from the file? It sounds like you're doing it in a much too complicated way ("read the file into a string, turn it into an array of bytes, ...").

In Java, you use Readers and Writers to read and write text files. Readers and Writers take care of decoding and encoding the data to and from Strings, using character encoding.

To read binary data, you should use an InputStream (for files, a FileInputStream).

Code:
InputStream in = new FileInputStream("myfile.dat"); byte[] buffer = new byte[1024]; int count = in.read(buffer); System.out.println("Read " + count + " bytes from the file"); in.close();
Look up FileInputStream in the Java API documentation.
Greetings.
Reply With Quote