File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes what is raw bytes ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is raw bytes ?" Watch "what is raw bytes ?" New topic

what is raw bytes ?

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 386
I am trying to understand input stream.
When I want to read from a file, I can just use FileReader. I am never inputting bytes from a file. So when do I use InputFileStream to input bytes from a file ? Its possible, when I am trying to get data from a socket. Otherwise, its just character data. when do I need to provide bytes from a file ?
In other words, I always store character data in a file. Is there a situation, when I store bytes in a file ? So when do I need to read raw bytes from a file, when there is only character data contained in it ?
Secondly whats the difference between bytes and raw bytes ?

Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4629

While there is no technical difference, the adjective 'raw' is sometimes added to emphasize that the individual bytes do not represent values, but are part of some bigger whole.

As far as files are concerned, they always consist of raw bytes. A Reader provides functionality that converts these bytes into characters. You will come across a situation where you have to deal with the raw bytes when there is no class in the Java API or in some third party API you use, that will convert a bunch of bytes to the structure you intend to use.

Here is an example: I have been working on an editor that will allow me to modify one of my old RPG games. This game stores for example items (like potions, swords, boots, keys) in a files, one file per item. Now, the developers of the game could have chosen to store the information as characters, something like this:

This may be easy to read, but it takes up a lot of space. Especially if there are thousands of different items. Instead, the developers defined their own file format, which which bytes in the file mean what. For my editor, I have to read these bytes, and build objects out of them myself.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link:
subject: what is raw bytes ?
jQuery in Action, 3rd edition