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

    Default bufferedreader question, please help.


    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 online now Moderator
    Join Date
    Apr 2009
    Rep Power

    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
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: bufferedreader question, please help.

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

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

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

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, 02:56 PM
  3. use of BufferedReader?please help
    By Cosmos in forum New To Java
    Replies: 11
    Last Post: 07-17-2011, 04: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 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