如何使用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 38节贺卡简短祝福语