I’m new to java and I am making a login program (based on text file processing) as part of my Java assignment so far I have written this code but it only checks the first line in the text file. I have also tried to add a for loop but it didn’t work either.
Could you please help me fix this problem.
(username and password are separated by a tab character in the file that’s why I used this (user+”\t”+pass))
Already tried the web, I didn’t find any good tutorial.
FileInputStream fstream = new FileInputStream("file.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
if ((user+"\t"+pass).equals(strLine)) {System.out.println ("Sucess");}
}
the text file is so
x y
x z
x t
so when you enter x and y the program says Success but for x and z or t there is no result!
Here is the full class:
}
And the file.txt:
As you would expect, the console output is:
So the piece of code you posted does check all lines. Please paste the contents of your file and your user and password strings.