import java.io.File;

public class Test
{
public static void main(String args[]){
Test t = new Test();
delFolder("c:/bb");
System.out.println("deleted");
} //删除文件夹
//param folderPath 文件夹完整绝对路径 public static void delFolder(String folderPath) {
try {
delAllFile(folderPath); //删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); //删除空文件夹
} catch (Exception e) {
e.printStackTrace();
}
} //删除指定文件夹下所有文件
//param path 文件夹完整绝对路径
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
return flag;
}
if (!file.isDirectory()) {
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
temp.delete();
}
if (temp.isDirectory()) {
delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);//再删除空文件夹
flag = true;
}
}
return flag;
}
}

用java删除文件夹里的所有文件的更多相关文章

  1. 用java实现删除文件夹里的所有文件

    package com.org.improve.contact; import java.io.File; public class DeletePaper { /** * @param args * ...

  2. Java以流的方式将指定文件夹里的.txt文件全部复制到另一文件夹,并删除原文件夹中所有.txt文件

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...

  3. 将Temporary文件夹里的Logo文件转移到Logo文件夹

    /// <summary> /// 将Temporary文件夹里的Logo文件转移到Logo文件夹 /// </summary> /// <param name=&quo ...

  4. Matlab 读取文件夹里所有的文件

    (image = dir('D:\gesture\*.*'); % dir是指定文件夹得位置,他与dos下的dir用法相同. 用法有三种: 1. dir 是指工作在当前文件夹里 2. dir name ...

  5. php中如何上传整个文件夹里的所有文件?

    1.使用PHP的创始人 Rasmus Lerdorf 写的APC扩展模块来实现(http://pecl.php.net/package/apc) APC实现方法: 安装APC,参照官方文档安装,可以使 ...

  6. C++实现:把一个文件夹里的冗余文件(.txt)删除

    代码很简单,调用了MFC里的几个函数.这里的冗余判断,是要遍历文件内容,进行两两比较. 需要注意的地方有两点: 1.源文件里头文件<afx.h>必须放在最前面.这里是为了避免nafxcwd ...

  7. Android中res/layout文件夹里新建布局文件,R中不生成ID的奇葩错误

    新浪微博:http://weibo.com/u/1928100503 网上看了下,发现大都是xml文件名大写而导致的id不能生成的问题,但在下的问题却不是大小写的问题,在下发现,当你的layout目录 ...

  8. diff两个文件夹里的东西

    diff --help -x, --exclude=PAT               exclude files that match PAT 排除某个类型的文件 -u, -U NUM, --uni ...

  9. jq和js插件的各个文件夹里放置的内容

    1. demo文件夹,存放各种实例. 2. dist文件夹,全称是distribution.在某些框架中,因为开发和发布的内容或者代码形式是不一样的(比如利用Grunt压缩等等),这时候就需要一个存放 ...

随机推荐

  1. android获取手机信息大全

    IMEI号,IESI号,手机型号: private void getInfo() { TelephonyManager mTm = (TelephonyManager) getSystemServic ...

  2. mysql中int、bigint、smallint 和 tinyint的区别与长度的含义

    最近使用mysql数据库的时候遇到了多种数字的类型,主要有int,bigint,smallint和tinyint.其中比较迷惑的是int和smallint的差别.今天就在网上仔细找了找,找到如下内容, ...

  3. iOS CoreData学习资料 和 问题

    这里是另一篇好文章 http://blog.csdn.net/kesalin/article/details/6739319 这里是另一篇 http://hxsdit.com/1622 (不一定能访问 ...

  4. 【mysql】用navicat连接虚拟机mysql出现错误代码(10038)

    来源: http://www.cnblogs.com/ohmydenzi/p/5521121.html http://blog.csdn.net/chana1101/article/details/3 ...

  5. css3学习总结4--CSS3背景

    css3背景 1. background-size 2. background-origin 3. background-clip 示例: className { background:url(bg_ ...

  6. JQuery的AJAX封装加例子

    将json字符串转换为javascript对象有两种方法:var strs = eval("(" + data + ")");var strs = $.pars ...

  7. vector data() [c++11]

    Example 12345678910111213141516171819202122 // vector::data #include <iostream> #include <v ...

  8. redhat6.2下的ssh密钥免密码登录(原创)

    这个是我自己写的,鼓励转载,请说明转载地址:http://www.cnblogs.com/nucdy/p/5664840.html 在进行hadoop的免密码的登录操作是,老是发生no route等错 ...

  9. hdu 4003 树形dp+分组背包 2011大连赛区网络赛C

    题意:求K个机器人从同一点出发,遍历所有点所需的最小花费 链接:点我 Sample Input 3 1 1 //3个点,从1出发,1个机器人 1 2 1 1 3 1 3 1 2 1 2 1 1 3 1 ...

  10. GRE词汇3-4 +

    page3 accommodate: common commodity accompany: Accomplice:  com—共同 plic—重叠 Complicate duplicate repl ...