The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Quick question about while loops

Posted by Hiran on November 20, 2001 at 3:48 AM

If I have a while loop declared the following way:

BufferedReader fileIn = new BufferedReader(new FileReader("c:\\test.txt"));
String taskNumber;
while(!(taskNumber = fileIn.readLine()).equals(null)) {
//some code

what happens if the file test.txt contains nothing in it (ie, taskNumber equals null? As far as I know, it should break from the loop and (in this case) return to the method that called it (since there is nothing after the loop). Yet, it doesn't. It ends the application completely. If test.txt does contain text, then everything continues as normal. Does anyone know what's going on? If you want, I can send you the full code.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us