zoukankan      html  css  js  c++  java
  • 目录处理工具类 DealWithDir.java

    1. package com.util;  
    2.   
    3. import java.io.File;  
    4.   
    5. /** 
    6.  * 目录处理工具类 
    7.  * 
    8.  */  
    9. public class DealWithDir {  
    10.     /** 
    11.      * 新建目录 
    12.      */  
    13.     public static boolean newDir(String path) throws Exception {  
    14.         File file = new File(path);  
    15.         return file.mkdirs();//创建目录  
    16.     }  
    17.       
    18.     /** 
    19.      * 删除目录 
    20.      */  
    21.     public static boolean deleteDir(String path) throws Exception {  
    22.         File file = new File(path);  
    23.         if (!file.exists())  
    24.             return false;// 目录不存在退出  
    25.         if (file.isFile()) // 如果是文件删除  
    26.         {  
    27.             file.delete();  
    28.             return false;  
    29.         }  
    30.         File[] files = file.listFiles();// 如果目录中有文件递归删除文件  
    31.         for (int i = 0; i < files.length; i++) {  
    32.             deleteDir(files[i].getAbsolutePath());  
    33.         }  
    34.         file.delete();  
    35.           
    36.         return file.delete();//删除目录  
    37.     }  
    38.   
    39.     /** 
    40.      * 更新目录 
    41.      */  
    42.     public static boolean updateDir(String path, String newPath) throws Exception {  
    43.         File file = new File(path);  
    44.         File newFile = new File(newPath);  
    45.         return file.renameTo(newFile);  
    46.     }  
    47.       
    48.     public static void main(String d[]) throws Exception{  
    49.         //deleteDir("d:/ff/dddf");  
    50.         updateDir("D:\TOOLS\Tomcat 6.0\webapps\BCCCSM\nationalExperiment/22222", "D:\TOOLS\Tomcat 6.0\webapps\BCCCSM\nationalExperiment/224222");  
    51.     }  
    52.       
    53.       
    54. }  
  • 相关阅读:
    文件上传与下载/Mail
    监听器/国际化
    过滤器
    父类转为子类涉及到的安全问题
    连接池
    【MySQL】Windows10下的安装与配置
    【neo4j】关于出现The old parameter syntax `{param}` is no longer supported. Please use `$param` instead的问题
    关于GitHub上传超过100M文件方法
    记录一次在知道创宇公司的实习面试经历
    《机器学习实战(基于scikit-learn和TensorFlow)》第七章内容学习心得
  • 原文地址:https://www.cnblogs.com/swite/p/5168706.html
Copyright © 2011-2022 走看看