String path ="d:\\upload_test_test\\file"; //设置一个默认文件夹路径
File uploadFilePath = new File(path);
// 如果该目录不存在,则创建之
if(uploadFilePath.exists() == false) {
uploadFilePath.mkdirs();
System.out.println("路径不存在,但是已经成功创建了" + path);
}else{
System.out.println("文件路径存在" + path);
}
很简单,但还是要记住呢···
下面是当文件不存在的时候就自动创建
File file = new File(desfile);
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}