简体   繁体   中英

What is the best way to check if a string from a text file equals what's in JTextField?

I have to write a program that has a log-in window.
I need to check if the username and the password all satisfy what is written in a text file.

the text file which has named as: "pass" contains the following : Admin:icsPro8%

In my validUserName method, I wrote these two lines under the try block to extract what is in the text file "pass" :

try{
   InputFile = new Scanner(new FileInputStream("pass.txt"));
   String name = InputFile.nextLine();
}

But unfortunately, I got this error: "name has private access in java.awt.Component" why this happened ? and how to fix it ?

You have initialized the variable name inside try block, so you cannot access it outside the try block. If you want to access it globally try to declare it outside the try block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM