```java
File file = new File("d:\\test_file.txt");
if (file.exists()) {
System.out.println("file exists");
} else {
System.out.println("file not exists, create it ...");
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
判断有没有文件夹,无则创建
File dir = new File("d:\\test_dir");
if (dir .isDirectory()) {
System.out.println("dir exists");
} else {
System.out.println("不存在,创建一个");
dir .mkdir();
}