aspose file tools*
The moose likes Beginning Java and the fly likes java io Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java io" Watch "java io" New topic
Author

java io

Peter Piddle
Greenhorn

Joined: Jun 13, 2012
Posts: 26

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?
thanks.


Peter Piddle - Skype(peter.piddle)
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

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?
thanks.

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.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Peter Piddle
Greenhorn

Joined: Jun 13, 2012
Posts: 26

Hi Ana,
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?
Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
I am afraid I am going to send you back to the tutorials, however little you like them. No, that would be cruel.

Lots of other people struggle with input and output; the Scanner and Formatter classes make it easier, but they have drawbacks
  • They are only suitable for text files, not “binary” data.
  • You can’t append to a file, only overwrite it. Or at least I have never found out how to append anything.
  • A lot of people get confused about the nextLine() method, thinking it actually reads the next line.

  • 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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: java io