Peter Piddle wrote:hi.
i want to understand java io in detail as i am finding it a pretty terse and difficult topic. The tutorial at the official site nearly makes me sleep.
Can you someone suggest a good book over java io or suggest best possible way to go through java io?
Welcome to CodeRanch!
Have you tried any programming, or are you facing any issue regarding some specific concept?
Please TellTheDetails, and ShowSomeEffort.
I hope it helps.
I find the IO topic generally difficult. I am unable to grasp what is the difference between buffered reads and character streams.
What i always understood no matter what kind of stream it is eventually it is a byte for a computer. Additionally, i want to develop
some sample small application under File IO so that i understand the concepts more. Can you suggest any pointers in this direction?
Lots of other people struggle with input and output; the Scanner and Formatter classes make it easier, but they have drawbacks
A character stream deals with one character at a time. It is designed for text files, and will require an encoding (many use UTF-8 or ISO-8859-1 as a default). You can read about encodings in an article which is worth reading for its title alone: here, and you can find out about UTF-8 on the Unicode website.
A data stream handles 8‑bit bytes and is intended for things like image files which are not text of any sort. The problem with streams is that they read in small bits. One of the worst examples is System.in.read(), which I shall leave you to read about. It is worth trying it, just to see how annoying it is to use. So what you do is wrap them in a buffered stream, which collects lots of data in a memory buffer and passes it on to the program in large groups. This is much more efficient because IO, even to a disc, is a slow process.
You have to open every stream and make sure to close it after use. If you don’t, the location might be unavailable for use by anything else. There is another problem if you don’t close a writing stream: a few weeks ago somebody failed to close a writer and got another problem. But never close System.in, System.out and System.err, nor any readers and writers using them.
You will find some examples of opening and closing readers here; the process is very similar for writers.