简体   繁体   English

检查文本文件中的字符串是否等于JTextField中的字符串的最佳方法是什么?

[英]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.

相关问题 从 json 文本文件加载 JSONObject 的最佳方法是什么? - What’s the best way to load a JSONObject from a json text file? 拆分此文本文件的最佳方法是什么? - What's the best way to split this text file? 检查 String 是否包含 Java/Android 中的 URL 的最佳方法是什么? - What's the best way to check if a String contains a URL in Java/Android? 在 Java 中检查 String 是否代表整数的最佳方法是什么? - What's the best way to check if a String represents an integer in Java? 检查Reader是否为空的最佳方法是什么? - What's the best way to check if a Reader is empty? 从 .eml 文件中获取文本的最佳方法是什么? - What is the best way to get text from .eml file? 在File的Java IO中使用Delim的最佳方法是什么 - What's best way to use delim in Java IO from File 用Java标记文本文件的最佳方法是什么? - What is the best way to tokenize a text file in Java? 给定有效字符串的某些限制,在Java中分解文本文件的最佳方法是什么? - What is the best way to break up a text file in java given certain limitations on what a valid string is? 如果一段文字是垃圾邮件,那么检查Java的最佳,最简单,免费的方法是什么? - What's the best, easiest, free way to check in Java if a piece of text is spam?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM