Click to See Complete Forum and Search --> : BufferedReader (Java) detecting EOF
PolteRGeisT
01-14-2005, 03:45 PM
I need to use the BufferedReader class to read lines of text from a file, but I am having problems detecting the end of the file. I understand I can use the exception but this would be a bad way of doing it. I essentially want to open a file and read lines of text from it until the end of the file is reached. I've searched the Java documentation for this but have come up with nothing.
Arjay
01-14-2005, 04:15 PM
Maybe do something like a while loop.
line = inFile.readLine();
while ( ( line != null) {
inputTextArea.append(line+"\n");
line = inFile.readLine();
}
inFile.close();
or perhaps..
while ((line = inFile.readLine()) != null) {
inputTextArea.append(line+"\n");
}
inFile.close();
I had to look it up cos i couldn't remember, i can never remember stuff.
Hope that helps
PolteRGeisT
01-14-2005, 04:18 PM
D'oh. :( it WAS listed in the documentation, I just didn't read the full description for readLine(). Thanks for the help Arjay :)
Arjay
01-14-2005, 04:19 PM
No probs :)