Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

End of File

Hi,
How do i check for end of file in java?

Thanks
0
komlaaa
Asked:
komlaaa
1 Solution
 
sciuriwareCommented:
All reading methods return 0 or -1 on EOF or ERROR.
;JOOP!
0
 
sciuriwareCommented:
Some higher methods that would return an object will return   null.

Please choose a way of input and refer to JAVADOC.
Check out    .read  and .readln()  etc.
;JOOP!
0
 
aviadbdCommented:

Just to give an example to what sciuriware said:

suppose you're reading from the file byte after byte:

int n;

while ((n = fileIn.read()) != -1) {

   // process n, which now contains a character from the file stream

}


Aviad.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
zzynxSoftware engineerCommented:
0
 
mightyoneCommented:
or

File f = new File ("yourfile");
InputStream is = new FileInputStream(f);
int x = is.available();


x is the length of your file in bytes.... so if you reach your xth byte it is the last....
0
 
zzynxSoftware engineerCommented:
Thanks for accepting
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now