天天看点

Java 根据路径生成文件夹

private static boolean createPath(String path) throws Exception {  

File dirFile = null;  

try {  

dirFile = new File(path);  

if (!(dirFile.exists()) && !(dirFile.isDirectory())) {  

boolean creadok = dirFile.mkdirs();  

if (creadok) {  

System.out.println("OK: 创建文件夹成功! ");  

} else {  

                   System.out.println("ERROR: 创建文件夹失败! " + path);  

                 }  

else System.out.println("INFO: 文件夹已经存在! ");  

} catch (Exception e) {  

           e.printStackTrace();  

             System.out.println(e);  

             return false;  

}  

return true;  

记录于此,以便使用。