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

3388 1
LZH实名认证 2022-3-20 14:46:12 | 显示全部楼层 |阅读模式
以下实例演示了使用 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
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行