How recognize EOF in Java using standar input

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
danielgomez
New poster
Posts: 1
Joined: Sat Oct 18, 2008 5:17 pm

How recognize EOF in Java using standar input

Post 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.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: How recognize EOF in Java using standar input

Post by mf »

BufferedReader.readLine returns null on EOF, so what's exactly the problem with your program?
rs31337
New poster
Posts: 1
Joined: Sat Nov 28, 2009 1:22 am

Re: How recognize EOF in Java using standar input

Post 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..
Post Reply

Return to “Java”