java 删除文件夹中的所有文件及文件夹
删除文件夹(前提:文件夹为空以及InputStream和OutputStream等一些数据文件流关掉【close()】,否则文件无法删除)
- //删除文件夹
- 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();
- }
- }
删除指定文件夹下的所有文件
- 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 删除文件夹中的所有文件及文件夹的更多相关文章
- 键盘录入一个文件夹路径,统计该文件夹(包含子文件夹)中每种类型的文件及个数,注意:用文件类型(后缀名,不包含.(点),如:"java","txt")作为key, 用个数作为value,放入到map集合中,遍历map集合
package cn.it.zuoye5; import java.io.File;import java.util.HashMap;import java.util.Iterator;import ...
- 文件 "c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\ttt.mdf" 已压缩,但未驻留在只读数据库或文件组中。必须将此文件解压缩。 CREATE DATABASE 失败。无法创建列出的某些文件名。请查看相关错误。 (.Net SqlClient Data Provider)
问题: 文件 "c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\ttt.mdf" 已压缩,但 ...
- Js文件函数中调用另一个Js文件函数的方法
在项目中Js文件需要完成某一功能,但这一功能的大部分代码在另外一个Js文件已经完成,只需要调用这个文件实现功能.那么如何调用:一个Js文件函数中调用另一个Js文件函数的方法? (直接代码说明) 示例d ...
- C++工程文件夹中的bin和obj文件夹有何用处?(补充多文件结构)
博主在使用Code::Blocks创建一个工程之后,正准备新建一个头文件,细心的博主发现,在工程文件夹中有两个子文件夹,分别是bin和obj.好奇心驱使下,想知道这两个文件夹用来干嘛的,网上搜了下,整 ...
- python 读取文件夹中所有同类型的文件 并用pandas合并
import globimport osimport pandas as pd read_path = 'D:/Data' # 要读取的文件夹的地址read_excel = glob.glob(os. ...
- Java——删除Map集合中key-value值
通过迭代器删除Map集合中的key-value值 Iterator<String> iter = map.keySet().iterator(); while(iter.hasNext() ...
- win7在某个盘或文件夹中出现右键只能新建文件夹的情况 (2012-12-28-bd 写的日志迁移
至于只能新建文件夹的情况如图: 解决方法是在运行中输入msconfig进入如图: 在系统设置选工具项在选中更改UAC设置点击启动如图: 如图: 直接把通知栏拉到最低确定即可(如果已经是最低了那就随便改 ...
- Ubuntu 查找文件夹中内容包含关键字的文件,路径为当前文件夹
From CSDN http://blog.csdn.net/lizhenmingdirk/article/details/44834997 grep -rl "keyword" ...
- ubuntu14 查找并删除所有文件名中带有特定关键词的文件
http://askubuntu.com/questions/625219/how-to-search-and-delete-files-who-contain-specific-string-in- ...
- python当前工作文件夹中创建空的.txt文件
import os def new_txt(): a1='实线' b = os.getcwd() + '\\fazhandadao_test_txt\\' if not os.path.exists( ...
随机推荐
- C#检查网络是否可以连接互联网
添加引用: using System.Runtime.InteropServices; using System.Net.NetworkInformation; [DllImport("wi ...
- hive JDBC异常到多租户
hive jdbc执行select count(*) from test报错. return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedT ...
- 关于postman、postman interceptor的安装、配置问题
由于app中有一些鉴权问题,需要携带浏览器的cookie. 不然的话不能够正确测试接口,就在chrome(这里下载的来源是Google商店)中添加了postman interceptor插件. 然后发 ...
- mycat sequence
数据库方式原理在数据库中建立一张表,存放sequence名称(name),sequence当前值(current_value),步长(increment int类型每次读取多少个sequence,假设 ...
- Rails的静态资源管理(三)—— 开发环境的Asset Pipelin
官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...
- handlebars自定义helper方法
handlebars相对来讲算一个轻量级.高性能的模板引擎,因其简单.直观.不污染HTML的特性,我个人特别喜欢.另一方面,handlebars作为一个logicless的模板,不支持特别复杂的表达式 ...
- 原生的ado.net(访问sql server数据库)
本文介绍原生的ado.net(访问sql server数据库) 写在前面 数据库连接字符串 过时的写法 string str = "server=localhost;database=my_ ...
- 注解:@interface 自定义注解的语法
自定义注解: 使用@interface自定义注解时,自动继承了java.lang.annotation.Annotation接口,由编译程序自动完成其他细节.在定义注解时,不能继承其他的注解或接口 ...
- ks8基础(1) etcd安装
下载安装 https://github.com/coreos/etcd/releases 在这网页,可以看到有多个版本共选择. 下载3.25 解压后, cd etcd-v3.2.5-linux-amd ...
- Git中远程仓库的使用
1.查看当前的远程库 要查看当前配置有哪些远程仓库,可以用 git remote 命令,它会列出每个远程库的简短名字.在克隆完某个项目后,至少可以看到一个名为 origin 的远程库,Git 默认使用 ...