java创建文件和目录(二)

2014-11-24 09:26:26 · 作者: · 浏览: 12
      try {  
  •             if (file.createNewFile()) {  
  •                 System.out.println("创建单个文件" + destFileName + "成功!");  
  •                 return true;  
  •             } else {  
  •                 System.out.println("创建单个文件" + destFileName + "失败!");  
  •                 return false;  
  •             }  
  •         } catch (IOException e) {  
  •             e.printStackTrace();  
  •             System.out.println("创建单个文件" + destFileName + "失败!" + e.getMessage());  
  •             return false;  
  •         }  
  •     }  
  •      
  •      
  •     public static boolean createDir(String destDirName) {  
  •         File dir = new File(destDirName);  
  •         if (dir.exists()) {  
  •             System.out.println("创建目录" + destDirName + "失败,目标目录已经存在");  
  •             return false;  
  •         }  
  •         if (!destDirName.endsWith(File.separator)) {  
  •             destDirName = destDirName + File.separator;  
  •         }  
  •         //创建目录  
  •         if (dir.mkdirs()) {  
  •             System.out.println("创建目录" + destDirName + "成功!");  
  •             return true;