如何在Java中检查文件是否存在?
File类提供了 exist()方法,如果指定路径中的文件存在,则返回true,否则返回false。
示例
import java.io.File;public class FileHandling { public static void main(String args[]) { File file = new File("samplefile"); if(file.exists()) { System.out.println("Given file existed"); } else { System.out.println("Given file does not existed"); } }}输出结果
Given file does not existed
热门推荐
10 岁岁祝福语简短独特
11 预祝高尔夫的祝福语简短
12 写字生日祝福语简短独特
13 爱小姨文案祝福语简短
14 简短祝福语中考女孩的话
15 年底老板祝福语简短的
16 送给员工美好祝福语简短
17 牙医生日祝福语简短
18 祝福语简短创意闺蜜