Results 1 to 3 of 3
  1. #1
    javalearner2 is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default bufferedreader question, please help.

    hi

    I'm using bufferedreader to read a file now.
    How can I say, if the next line is null (without jumping to the next line ), then do something. (say, print helloworld)

    It's like, i want to have a function "boolean hasNextLine()". Please provide me the code and syntax if you can.
    Thank you.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: bufferedreader question, please help.

    You can't.
    Here's the API for BufferedReader.
    All you have (on top of the standard read() methods) is a readLine() method.
    It doesn't have a way to test whether there's a line.
    If you think about it a while you'll see that that would not be possible in most cases where the BufferedReader would be used to wrap a stream.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: bufferedreader question, please help.

    If you accept a restriction (a maximum line length), it can be done:

    Java Code:
    br.mark(maxlineLength);
    boolean hasLine= br.readLine() != null;
    br.reset();
    But I find this whole thing a sily academic exercise with no practical use ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Using BufferedReader
    By hqt in forum New To Java
    Replies: 1
    Last Post: 12-09-2011, 05:12 AM
  2. How to use BufferedReader?
    By ProgramBeginner in forum New To Java
    Replies: 4
    Last Post: 10-11-2011, 03:56 PM
  3. use of BufferedReader?please help
    By Cosmos in forum New To Java
    Replies: 11
    Last Post: 07-17-2011, 05:55 PM
  4. BufferedReader, need help!
    By zacharyrod in forum New To Java
    Replies: 10
    Last Post: 11-19-2009, 11:56 AM
  5. BufferedReader
    By vidhya.sk in forum New To Java
    Replies: 2
    Last Post: 09-18-2008, 02: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
  •