Java读取txt文件内容做判断
答案:1 悬赏:50
解决时间 2021-01-26 06:03
- 提问者网友:欺烟
- 2021-01-26 00:05
Java读取txt文件内容做判断
最佳答案
- 二级知识专家网友:孤独的牧羊人
- 2021-01-26 01:31
import java.io.*;
public class Demo1 {
private static final String SystemPassword = "123456";
public static void main(String[] args) {
String password = readPasswordFromFile("abc.txt");
if(SystemPassword.equals(password)) {
System.out.println(password);
} else {
System.out.println("密码不正确。");
}
}
public static String readPasswordFromFile(String filePath) {
try {
File file = new File(filePath);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
reader.close();
return line;
} catch (Exception e) {
return "";
}
}
}追问没学过 19行以后的知识,能不能用输出流和输入流的知识 写
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯