java创建文件和目录(三)

2014-11-24 09:26:26 · 作者: · 浏览: 8
  •         } else {  
  •             System.out.println("创建目录" + destDirName + "失败!");  
  •             return false;  
  •         }  
  •     }  
  •      
  •      
  •     public static String createTempFile(String prefix, String suffix, String dirName) {  
  •         File tempFile = null;  
  •         if (dirName == null) {  
  •             try{  
  •                 //在默认文件夹下创建临时文件  
  •                 tempFile = File.createTempFile(prefix, suffix);  
  •                 //返回临时文件的路径  
  •                 
    return
     tempFile.getCanonicalPath();  
  •             } catch (IOException e) {  
  •                 e.printStackTrace();  
  •                 System.out.println("创建临时文件失败!" + e.getMessage());  
  •                 return null;  
  •             }  
  •         } else {  
  •             File dir = new File(dirName);  
  •             //如果临时文件所在目录不存在,首先创建  
  •             if (!dir.exists()) {  
  •                 if (!CreateFileUtil.createDir(dirName)) {  
  •                     System.out.println("创建临时文件失败,不能创建临时文件所在的目录!");  
  •                 &nb