Java 根据路径生成文件夹

来源:互联网 发布:最小linux系统 编辑:程序博客网 时间:2024/05/17 22:21

 

/**

     * 生成文件夹

     *

     * @param path

     * @return

     * @throws Exception

     */  

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;  

 

记录于此,以便使用。