Problem when reading files
Im new in programming and I'm having a problem with a work I have to do, and I really need someone to tell me what I'm doing wrong.
To sum up, what I have to do is to simulate a login system, so I created a class which has that funcionality, the 'login' method.
By reading a file with Buffered reader, I have to enter with keyboard a code and a password, and then It has to check if they match (there are 2 codes and 2 passwords, each code associated to a password)
The file is something like this (not this actually)
Taking in count that I cant change anything in the file, how could I do it?
What ive done is, by using 4 variables (passw, code, passwfile, codefile, 2 of them are filled by keyboard) I'd like to compare passw and code with passwfile and codefile, which are filled by reading the file.
Well, the problem is that I dont know how to assign to passwfile and to codefile the right line of the file in order to compare them with passw and code.
(Sorry for my bad english, it's not my native language)
If you need part of my code I'll post it.
Re: Problem when reading files
You will need to take input from the User, which you could do with the Scanner class. You then need to read a text file and check if what the user entered matches any password/username combination - You can also do that with the Scanner class.
You can read more about it here:
Scanner (Java 2 Platform SE 5.0)
Scanning (The Java™ Tutorials > Essential Classes > Basic I/O)