- package com.util;
- import java.io.File;
- /**
- * 目录处理工具类
- *
- */
- public class DealWithDir {
- /**
- * 新建目录
- */
- public static boolean newDir(String path) throws Exception {
- File file = new File(path);
- return file.mkdirs();//创建目录
- }
- /**
- * 删除目录
- */
- public static boolean deleteDir(String path) throws Exception {
- File file = new File(path);
- if (!file.exists())
- return false;// 目录不存在退出
- if (file.isFile()) // 如果是文件删除
- {
- file.delete();
- return false;
- }
- File[] files = file.listFiles();// 如果目录中有文件递归删除文件
- for (int i = 0; i < files.length; i++) {
- deleteDir(files[i].getAbsolutePath());
- }
- file.delete();
- return file.delete();//删除目录
- }
- /**
- * 更新目录
- */
- public static boolean updateDir(String path, String newPath) throws Exception {
- File file = new File(path);
- File newFile = new File(newPath);
- return file.renameTo(newFile);
- }
- public static void main(String d[]) throws Exception{
- //deleteDir("d:/ff/dddf");
- updateDir("D:\\TOOLS\\Tomcat 6.0\\webapps\\BCCCSM\\nationalExperiment/22222", "D:\\TOOLS\\Tomcat 6.0\\webapps\\BCCCSM\\nationalExperiment/224222");
- }
- }
|
作者:候鸟 出处:http://www.cnblogs.com/swite/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
浙公网安备 33010602011771号