Results 1 to 2 of 2
  1. #1
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Java i/o confusion

    hello,

    i want to read a file. (text)

    and now i am hopelessly confused over all the i/o file/ input/ reader classes.

    In a later version I want to be able to set the (UniCode)Character set but what is the diffrence between

    java.io.FileInputStream
    java.io.BufferedInputStream
    java.io.BufferedReader
    java.io.Reader
    java.io.FileReader

    and how do i combine them all?

    do i do fileinputstream-> buffer-> reader
    or

    2 related questions.

    1) I also would like to include:

    javax.swing.ProgressMonitorInputStream (to see the progress of the input)

    do i do fileInputStream-> monitor -> buffer-> reader
    or fileinputstream-> buffer -> monitor -> reader
    or fileinputstream-> monitor -> reader -> buffer
    or even another variation?

    2) which classes do I declare as instance variables (defined in class, private) and which as temporarely objects (declared in the constructor)

    Thanks in advance

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by willemien View Post
    i want to read a file. (text)

    and now i am hopelessly confused over all the i/o file/ input/ reader classes.
    There are two types of input streams: byte oriented (all the InputStreams take care of that) and character oriented (all the Readers take care of it). There's bridge that converts a byte oriented input stream to a character oriented inputstream: the InputStreamReader. It needs an encoding to convert those bytes to characters. A default encoding is also available. So if you want to read text (characters) with a certain encoding you open a FileInputStream (assuming you want to read from a file); this gives you a byte oriented input stream. Wrap it in an InputStreamReader with the encoding you want to use; this gives you a character oriented stream. If you want to can wrap that reader in another reader, e.g. a BufferedReader to speed up the actual reading.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Confusion here @@' Help!
    By pleasurelyours in forum New To Java
    Replies: 7
    Last Post: 06-09-2010, 03:42 PM
  2. java API (SE) version confusion
    By Arnold in forum New To Java
    Replies: 3
    Last Post: 04-30-2010, 10:42 AM
  3. confusion with Design Pttern in java
    By sandeepsai39 in forum New To Java
    Replies: 2
    Last Post: 11-23-2009, 07:45 AM
  4. Tic Tac Toe confusion
    By jigglywiggly in forum New To Java
    Replies: 15
    Last Post: 04-12-2009, 01:47 AM
  5. Confusion over arrays
    By dbashby in forum New To Java
    Replies: 5
    Last Post: 04-04-2009, 09:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •