This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ?
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.