Skip to content
Advertisement

how to compare input with file data

I’m trying to compare user input name to the exists names in the file javaFx if it the same name will get alert if not another window will appear. but I always get new window even if the name exists any suggestion?

JavaScript

Advertisement

Answer

You want to display an alert if the same is already present in the info.txt file. Otherwise, you want to open another window. The way your method has been written, it does not do that. There are too many logical flaws in your code.

Here is the while loop that you have used. I have added comments to make each task more clear to understand.

JavaScript

The last break statement is the problem. What is happening here is, you check if the first name in the file matches the input name. If it does, show alert, else show new window. Your method will not check any other name in the file with the input name. It’s easy to figure out why that happens.

If you want to check all the names in the file against the input name and then, if none of the name matches the input name then do what you stated. Here is the way that will work.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement