用java写一个判断.txt的文件

用java写一个判断.txt的文件,第1张

File file = new File("a.txt")

if(file.getName().endsWith(".txt")) {

    System.out.println("是txt文件")            

}

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 ""

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/8023380.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存