package com.tij.io.file;
import java.io.File;
import java.io.IOException;
/**
* 判断文件存在目录
* @author guoyoujun
* @date 2014-3-17
*/
public class FileExists {
/**
* java.io.File类的exists()方法可以检查该文件否存在目录中
* <p>返回true则存在,返回false则不存在
* @param args
*/
public static void main(String[] args) {
File file = new File("/Users/GYJ/java1.txt");
File notExist = new File("abc.txt");
try {
//file.getCanonicalPath()表示文件的全路径
System.out.println(file.getCanonicalPath() + " exist? " + file.exists());
System.out.println(notExist.getCanonicalPath() + " exist? " + notExist.exists());
} catch (IOException e) {
e.printStackTrace();
}
}
}
out put==========
C:\Users\GYJ\java1.txt exist? true
C:\Users\GYJ\workspace\java_workspace\io\abc.txt exist? false