How can i read single line from a text file in java. and what is the criteria of knowing that line is completed.
secondly
i read file and then for Read Line
First thing : readLine() returns String value only so it is not converting to String.
Second thing : In your while loop, you read firstline and check whether the content of first line is null or not. But when data = infile.readLine(); executes, it will fetch second line from file and print it to Console.
Change your while loop to this :
while((data = infile.readLine()) != null){
System.out.println(data);
}
If you use toString() method, it will throw NPE when it will try to use toString method with null content read from infile.