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

[1938 byte] By [Jazmana] at [2007-11-26 14:37:56]
# 1
String is an object. You cannot compare a string with another one using ==. Instead, changeif ((inLine.toString()) == var)toif ((inLine.toString()).equals(var))
Lord_Jirachia at 2007-7-8 8:19:00 > top of Java-index,Java Essentials,New To Java...
# 2
Works perfect now. Thank you for the explanation.
Jazmana at 2007-7-8 8:19:00 > top of Java-index,Java Essentials,New To Java...
# 3

Good day Friend!

Your approach is good and excellent

i used to used java.util.scanner package to perform some

operation at console

My best advice is to use scanner class

If you need any help ,just buzz me

i will help you

with regards

vasu_gb@yahoo.co.in

vasu_gba at 2007-7-8 8:19:00 > top of Java-index,Java Essentials,New To Java...
# 4
Thank you very much vasu. I appreciate your advice and your offer for help. I am having an problem detailed in the following thread. http://forum.springframework.org/showthread.php?p=94873&posted=1#post94873I would really appreciate your input.
Jazmana at 2007-7-8 8:19:00 > top of Java-index,Java Essentials,New To Java...