Comparing a Variable with Characters in a File
Hello,
I've the following code;
import java.io.*;
publicclass Compare{
static String var ="guest";
publicstaticvoid main(String[] args){
try{
BufferedReader in =new BufferedReader(new FileReader("C:/Documents and Settings/Jaz/workspace/Tutorial/README_InputFile.txt"));
String inLine =null;
while ((inLine = in.readLine()) !=null){
if ((inLine.toString()) == var)
System.out.println(inLine);
}
in.close();
}catch (IOException e){
System.out.println("IOException:");
}
}
}
Im trying to compare the variable "var" with each line of a text file. There is a line in the text file with the characters "guest". What I would expect to happen is that when interpreter, in while loop, gets round to reading this line, it makes a successful comparison between var and inLine and displays guest on the console. However nothing appears on the console. Im not sure why this is. Can anyone point me in the right direction?
Thanx
Message was edited by:
Jazman

