[英]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% 名为:“ pass”的文本文件包含以下内容: Admin:icsPro8%
In my validUserName method, I wrote these two lines under the try block to extract what is in the text file "pass" : 在我的validUserName方法中,我在try块下编写了这两行,以提取文本文件“ 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 ? 但是不幸的是,我得到了这个错误:“名称在java.awt.Component中具有私有访问权限”为什么会发生这种情况? and how to fix it ? 以及如何解决?
You have initialized the variable name inside try block, so you cannot access it outside the try block. 您已经在try块内初始化了变量名,因此无法在try块外访问它。 If you want to access it globally try to declare it outside the try block. 如果要全局访问它,请尝试在try块外声明它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.