Results 1 to 5 of 5
  1. #1
    Abder-Rahman is offline Member
    Join Date
    Oct 2008
    Posts
    32
    Rep Power
    0

    Default BufferedReader/InputStreamReader - NON-TECHNICAL

    Hello,

    I'm using this line of code in order to read a line of text.

    BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));


    I returned to the Java documentation in order to understand it, but it was too technical.

    What does the preceding line of code trying to tell us in an easy language?

    Thanks.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    System.in is an InputStream, which means that it reads the input in bytes.

    InputStreamReader is a Reader "wrapper" around this InputStream which then allows you to read characters, i.e. it is a Character stream, rather than a byte stream.

    BufferedReader is a wrapper around the InputStreamReader which simply buffers the input which can, and usually does, bring performance benefits.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Well, "System.in" is a static member of the System class of the type InputStream. InputStream is designed to allow you to read 8 bit bytes.

    Then we have a couple of examples of "wrapping" where additional capabilities are added to the stream. First a reader (an InputStreamReader) is constructed: readers allow the input to be interpreted as a series of characters in the local character set.

    Finally the stream (now capable of dealing with specifically encoded characters) is made to be buffered: that is it will get its data from an area in memory rather the much slower operation of getting the data from disk or network etc. When the memory buffer starts to get empty a whole lot of data will be obtained from the slower network or disk resource all at once.

    I returned to the Java documentation in order to understand it, but it was too technical.

    What does the preceding line of code trying to tell us in an easy language?
    Basically the line of code you quoted is technical and there's just no getting around that. But it is possible to understand it: I would suggest having a look at IO Streams in Sun's Tutorial.

    The first few sections deal precisely with the concepts exemplified in that line of code. And other parts of the Tutorial deal with various other parts of Java syntax involved. The language and approach of the tutorial is designed to be accessible in a way that the API documentation sometimes isn't, so if there is something in the material linked to that you can't understand: ask.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Quote Originally Posted by Fubarable View Post
    note that this was cross-posted at javaranch
    Personally this annoys the h3ll out of me.

    This question - possibly even more than most - involves someone moving from where they are now to somewhere where they have more understanding. The ideas involved are technical, but not rocket science. It's the poster not the answer that's important.

    All of which means that there can be little progress without an exchange of ideas, observations, questions and suggestions. And I'm fsked if I am going to go all around the internet to follow the ideas, observations, questions and suggestions being thus exchanged.

    OP: why don't you post in one place? And engage in an actual dialogue? Or, at any rate post links which make it clear to anyone who takes the time to reply to your question, that the discussion as a whole is taking place elsewhere.

Similar Threads

  1. How to use BufferedReader?
    By ProgramBeginner in forum New To Java
    Replies: 4
    Last Post: 10-11-2011, 03:56 PM
  2. Problem with in InputStreamReader, pls help
    By hyperkossan in forum New To Java
    Replies: 0
    Last Post: 12-10-2008, 09:50 PM
  3. B2B Technical Lead (Contract to Perm)
    By subhasis.patro@gmail.com in forum Jobs Offered
    Replies: 0
    Last Post: 09-19-2008, 08:52 PM
  4. Replies: 0
    Last Post: 07-15-2008, 01:51 PM
  5. Requirement for Technical Professionals
    By deepak_yoganishta in forum Jobs Offered
    Replies: 0
    Last Post: 02-04-2008, 02:08 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
  •