Results 1 to 8 of 8

Thread: EOF methode

  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default EOF methode

    Hello,

    I am reading a text file using FileReader and BufferedReader.
    Is there a way a checking the EOF ?

    I set an EOF attrubute to true when
    Java Code:
    br = BufferedReader(fr);
    br.readLine() == null;
    .

    Is there another way of checking the EOF
    ex : br.EOF;

    thanks

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

    Default

    Quote Originally Posted by Dipke View Post
    Hello,

    I am reading a text file using FileReader and BufferedReader.
    Is there a way a checking the EOF ?

    I set an EOF attrubute to true when
    Java Code:
    br = BufferedReader(fr);
    br.readLine() == null;
    .

    Is there another way of checking the EOF
    ex : br.EOF;

    thanks
    Did you find such method in the API documentation?

    kind regards,

    Jos

    ps. Java (nor C, nor C++) can predict an eof-condition. Pascal used to be able to do this.

  3. #3
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Hello,
    No i did not, but perhaps there is a method with another name that does the job.
    Or there is another way of checking.

    Grz

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Java Code:
    try{
    while(true){
    // code here
    }
    }
    catch(EOFException e){}

  5. #5
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Thanks for the reply

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

    Default

    Quote Originally Posted by Dipke View Post
    Thanks for the reply
    The code in the previous reply doesn't always work, i.e. there are methods that return -1 or null when they have bumped into an end of file and no exception is thrown. Read the API documentation for the InputStream and Reader classes instead.

    kind regards,

    Jos

  7. #7
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Thanks jos,

    I am still using my code that is working.
    Java Code:
    br.readLine() == null;
    I am used to work with VB en RealStudio.
    There is an EOF.
    Therefore i was just wondering if there was a similar thing in Java.

    Kind regards
    Dimi

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

    Default

    Quote Originally Posted by Dipke View Post
    Thanks jos,

    I am still using my code that is working.
    Java Code:
    br.readLine() == null;
    I am used to work with VB en RealStudio.
    There is an EOF.
    Therefore i was just wondering if there was a similar thing in Java.

    Kind regards
    Dimi
    In Java there is no such thing as an 'end of file' character and nor is there physically one in a file. There is an end of file condition and it is shown to you by the return value of the method if it can do so. Methods that can't return such a 'sentinel' value have to throw en EndOfFileException. Just play the game by the rules and everything will be fine.

    kind regards,

    Jos

Similar Threads

  1. using paint methode in another class
    By imorio in forum New To Java
    Replies: 8
    Last Post: 08-12-2010, 03:17 PM
  2. calling methode with array
    By koddy in forum New To Java
    Replies: 0
    Last Post: 06-30-2010, 01:53 PM
  3. Get "Frame"(?) as a methode
    By Mattedatten in forum New To Java
    Replies: 3
    Last Post: 11-10-2009, 12:31 PM

Tags for this Thread

Posting Permissions

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