Page 1 of 1

How recognize EOF in Java using standar input

Posted: Sat Oct 18, 2008 5:29 pm
by danielgomez
Hi, im doing some problems but i dont really now how recognize the EOF in Java.

If i use this to read from standar input:

Code: Select all

                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		
		while ((line = br.readLine())!= null ){
			/*
                        */
		}
	}
Can anyone help me .. Thanks.

Re: How recognize EOF in Java using standar input

Posted: Sat Oct 18, 2008 6:01 pm
by mf
BufferedReader.readLine returns null on EOF, so what's exactly the problem with your program?

Re: How recognize EOF in Java using standar input

Posted: Sat Nov 28, 2009 1:27 am
by rs31337
danielgomez wrote:Hi, im doing some problems but i dont really now how recognize the EOF in Java.

If i use this to read from standar input:

Code: Select all

                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		
		while ((line = br.readLine())!= null ){
			/*
                        */
		}
	}
Can anyone help me .. Thanks.
your doing it correct... however your syntax is messed up (i think) instead of "while ((line = br.readLine())!= null )" it should be

Code: Select all

String line = br.readLine();
while(line != null)
{
  //Your code
  line = br.readLine();
}
I could be wrong but I never assigned a value and checked a condition at the same time..