wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is raw bytes ?" Watch "what is raw bytes ?" New topic
Author

what is raw bytes ?

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 363
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 ?

Thanks
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3578
    
  14

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is raw bytes ?
 
Similar Threads
sample JSP code to upload file into database?
InputStream to multiple Readers
diff. Bw streams
Understanding Byte Data and Character Encoding
character convertion in java