• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading Binary files  RSS feed

 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I load a binary file, would that file display only 1's and 0's, no matter what kind of file I load(image, text file, jpg, etc)? When I load a file as a binary file, which read method should I use? At the moment I'm using readByte, but I'm not sure if thats the right one to use. Thanks in advance.
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A binary file means that it is not a file that can be (simply) read by looking at the contents.

It means that it is formatted in such a way that is specific for a computer (program) to understand it.

It does not mean that if you open it in a simple texteditor that it contains only one's and zero's. Remember, 8 bits is 1 byte. This means that the texteditor will show you the characters that represent the byte.

You can read a binary file with whatever method you would like. InputStreams deal with bytes however. So if you want to printout the binary content of a file you will have to translate the byte to a binary number. eg. byte value = 4 --> binary value = 0100
[ September 08, 2006: Message edited by: Manuel Moons ]
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

in java.io, Streams are good to read the bytes and Readers are good to read teh characters.

But it is upto your program how to read and manage the bits.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!