Question : Match string to a string Java

I have a text file with usernames.

I want to use a Scanner statement to read the text file and save all of the data/words in a string called saved_DB.

After which i want to prompt a user to key in his/her username. With the username given, I want to check if there is any record in saved_DB. If yes I want to print out the username. If not, I want it to print user not found.

How do I go about it. Im using Java.

Answer : Match string to a string Java

because you are not getting the file data correctly

<<while(findFile.hasNextLine()){
                      data = findFile.nextLine();
                      saved_data = data;
                }
>>

It should be replaced by
StringBuilder text = new StringBuilder();
while(findFile.hasNextLine()){
                      text.append( findFile.nextLine() );
                }

saved_data = text.toString();
Random Solutions  
 
programming4us programming4us