DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Posts
    3

    'end of file' in JAVA

    Hi!

    How do we check for the 'end of file' in JAVA?

    When we open a file and wish to read it till the end, we need to check for the end of file, right? [in C (while(!feof()))] How is that done in JAVA?

    thanks!

    -Trixie

  2. #2
    Join Date
    Mar 2003
    Posts
    84
    well one way to check for it is just to read the file line by line by line and check for null.


    for instance if you are loading a line of your file into a string called testThis,

    just use the loop

    while(testThis != null)
    {
    do what you want to do here.;
    }
    someFile.close();

    I usually just do it the same as in C and write


    while(!tesThis.atEOF())
    {
    do stuff.
    }
    someFile.close()

    and then write the method atEOF()

    public boolean atEOF()
    {
    if(this.getData = null)
    return true
    else
    return false
    }
    I'm surprised more of you people don't get hit by cars.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links