Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By JosAH

Thread: use of BufferedReader?please help

  1. #1
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Question use of BufferedReader?please help

    hi,i am new to this forum and i am finding it really exciting....

    i want to clear one of my doubts.....

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

    System.in is used to obtain byte stream from standard input,i.e.keyboard

    InputStreamReader is a subclass of Reader which is used to convert byte stream into character Stream...

    what is the use of BufferedReader in this statement then?????

    and one more question can you please explain me what does System.in means?

    that is i know what is System.out.println means,but i want to know what System.in means.....

    please explain like this-

    System-it is a class in java.lang package

    out-it is an object of type PrintStream in System class(PrintStream contains println method)....

    so to acess println method through static System class we use System.out.println()....

    please explain System.in in the same way....

    thanks in advance....

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

  3. #3
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default

    i read all the related topics on the internet but couldnt understand,therefore i posted it here....

    please explain in your own words....

    thanks in advance.....

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

    Default

    Quote Originally Posted by Cosmos View Post
    please explain in your own words....
    My own words: please (re)read the link supplied by Darryl Burke.

    kind regards,

    Jos
    sunde887 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default

    i read that stuff dude......everything regarding that on internet....i am not getting it....therefore i asked here.....this is the 1st link that you get whenever you type anything related to java on google.....

    if you know about this topic then please shed some light on it.....the thing written on the link is what i already know.....

    please read my question first....

    i asked two qeustions
    1.use of bufferedreader
    2.working of system.in

    and the link doesnt answer this....

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    In order so we don't have to write a complete chapter in a book, at this point you're far better off telling us in detail the specifics of what about the API documentation confuses you.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default

    working of system.in
    I assume you mean: System.in
    System is a class
    in is a variable in that class. The API doc tells you what class it is.

  8. #8
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default

    but in is a variable of InputStream class i suppose....i want to know how this code executes-

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

    what i want to know is how the input is taken from keyboard and how different conversions are performed to make the input into string format finally????

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default

    how the input is taken from keyboard
    in is connected to The "standard" input stream.
    new BufferedReader(new InputStreamReader(System.in));
    The constructor for those two classes make the conversions. Read the API doc for each to see what each class will do.

  10. #10
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    That doesn't read a line, instead it allows you to read something. The buffered reader wraps the input stream reader to add functionality to an existing class(look up the decorator pattern). Think of where System.out displays information, now try and figure out what System.in does(hint: it's the inverse of out at the same location).

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

    Default

    Quote Originally Posted by Cosmos View Post
    but in is a variable of InputStream class i suppose....i want to know how this code executes-

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

    what i want to know is how the input is taken from keyboard and how different conversions are performed to make the input into string format finally????
    The BufferedReader and the InputStreamReader add functionality (the "conversions") to an InputStream; the value System.in is an object of type InputStream and it is magically connected to your keyboard by the operating system which is none of the business for Java programmers.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by JosAH View Post
    ...the value System.in is an object of type InputStream and it is magically connected to your keyboard by the operating system...
    [nitpick]
    It connects magically to the standard input stream which may be coming from the keyboard, but may also be redirected from somewhere else, for instance from another program if need be (which is one way to have another running program "talk" to your Java program).
    [/nitpick]

Similar Threads

  1. How to use BufferedReader?
    By ProgramBeginner in forum New To Java
    Replies: 4
    Last Post: 10-11-2011, 02:56 PM
  2. BufferedReader
    By Nerijus in forum New To Java
    Replies: 4
    Last Post: 04-26-2010, 07:28 PM
  3. BufferedReader, need help!
    By zacharyrod in forum New To Java
    Replies: 10
    Last Post: 11-19-2009, 10:56 AM
  4. problem with BufferedReader
    By Ozmosis in forum Networking
    Replies: 6
    Last Post: 10-29-2009, 09:07 PM
  5. BufferedReader
    By vidhya.sk in forum New To Java
    Replies: 2
    Last Post: 09-18-2008, 01:57 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
  •