I have the following method, which takes in an integer & string. In addition, i have to compare the parameters with what is read from a text file. I get the error 'incompatible types'. Do I have to do some parsing? If so, how? From what i understand, parsing is not required with readLine(). The ideas is that I have to scan a text file for a valid staffId & go to the next line to check the associated password as well.
public boolean staffExists (int staffid, String staffpwd) throws IOException
{
boolean valid = false;
String filePath = new File("").getAbsolutePath();
BufferedReader reader = new BufferedReader(new FileReader(filePath + "/src/DBTextFiles/Administrator.txt"));
try
{
String line = null;
while ((line = reader.readLine()) != null)
{
if (!(line.startsWith("*")))
{
//System.out.println(line);
//http://stackoverflow.com/questions/19874621/how-to-compare-lines-read-from-a-text-file-with-integers-passed-in
if (line.equals(String.valueOf(staffid)) && (reader.readLine() == staffpwd))
{
System.out.println ("Yes");
System.out.println ("Welcome " + reader.readLine() + "!");
valid = true;
}
}
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
reader.close();
}
return valid;
}