Java 教程 Java 实例 - 检测文件是否存在

alexis · 2022-06-11 14:20:01 · 热度: 10

以下实例演示了使用 File 类的 file.exists() 方法来检测文件是否存在:

Main.java 文件

import java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/java.txt"); System.out.println(file.exists()); } }

以上代码运行输出结果为(如果你的 C 盘中存在文件 java.txt):

true

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册