如何使用Java检查文件的存在?
文件类提供了一个名为exist()的方法,如果当前文件对象中指定的文件存在,则该方法返回true。
示例
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 作品棒棒哒祝福语简短