本篇博客主要介绍递归在File类中的其他应用
package com.javaxl.io.file; import java.io.File; /** * @author 小李飞刀 * @site www.javaxl.com * @company * @create 2019-06-12 21:49 */ public class FileRemoveDemo { public static void main(String[] args) { File file = new File("E:\\testDir"); // file.delete(); 直接删文件夹,当文件夹非空的情况下是干不掉的 removeFile(file); } public static void removeFile(File file) { for (File listFile : file.listFiles()) { if(listFile.isDirectory()){ removeFile(listFile); }else { System.out.println(listFile + "---fileDelete---" + listFile.delete()); } } System.out.println(file + "---【dirDelete】---" + file.delete()); } }
注意:
1. 注释else会出现误删除的现象,一个文件会被删除两次;
2. Java所删除的文件不会进回收站;
3. Java对有些隐藏的文件夹无法访问;
非常实用的小程序,生成指定文件夹的文件清单
package com.javaxl.io.file; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * @author 小李飞刀 * @site www.javaxl.com * @company * @create 2019-06-12 22:01 * * 指定文件目录下特定文件生成文件清单 */ public class FileListCreateDemo { public static void main(String[] args) throws IOException { File dir = new File("E:\\2018_y2_讲课\\t216"); List<File> list = new ArrayList<>(); dirFiles2List(dir,list); ListWriteFile(list,"E:\\t216_ev4录屏清单.txt"); } /** * 将dir下的以.mp4结尾的文件放入list集合中 * @param dir * @param list */ public static void dirFiles2List(File dir, List<File> list) { for (File file : dir.listFiles()) { if(file.isDirectory()){ dirFiles2List(file,list); }else { if(file.getName().endsWith(".mp4")){ list.add(file); } } } } /** * 将list容器中符合条件的视频写到名称为fileName的清单文件中 * @param list * @param fileName */ public static void ListWriteFile(List<File> list,String fileName) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(fileName)); for (File file : list) { bw.write(file.toString()); bw.newLine(); bw.flush(); } bw.close(); } }
生成的清单文件中内容如下
E:\2018_y2_讲课\t216\14、Android(10)\10 PullToRefresh\vue与angular.mp4 E:\2018_y2_讲课\t216\14、Android(10)\10 PullToRefresh\上拉刷新.mp4 E:\2018_y2_讲课\t216\14、Android(10)\2、view与viewgroup\bandicam 2018-10-13 09-57-48-394.mp4 E:\2018_y2_讲课\t216\14、Android(10)\7、高级控件01 自动提示文本框与下拉列表\20181022_181714.mp4 E:\2018_y2_讲课\t216\14、Android(10)\7、高级控件01 自动提示文本框与下拉列表\20181022_181827.mp4 E:\2018_y2_讲课\t216\14、Android(10)\8、jackson和httpcliet\httpclient&&json.mp4 E:\2018_y2_讲课\t216\14、Android(10)\9、高级控件ListView\listview.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\01 struts2入门\1、入门以及动态方法调用.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\01 struts2入门\2、与j2ee交互(传参).mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\02 ognl\0、回顾.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\02 ognl\1、struts的ognl原理.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\02 ognl\2、上节课疑问解决.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\04、struts值crud\1、crud.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\05、拦截器与文件上传\1、struts拦截器.mp4 E:\2018_y2_讲课\t216\15、struts2(7-2)\05、拦截器与文件上传\2、struts上传下载.mp4 E:\2018_y2_讲课\t216\16、Maven(1)\0、回顾.mp4 E:\2018_y2_讲课\t216\16、Maven(1)\1、maven之struts.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\01 hibernate入门\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\01 hibernate入门\1、hibernate的新增.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\01 hibernate入门\2、hibernate查删改.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\02 主键生成策略\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\02 主键生成策略\1、hibernate主键生成策略.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\03 hibernate加载策略\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\03 hibernate加载策略\1、加载策略.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\04 一对多\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\04 一对多\1、一对多关系讲解.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\05 多对多\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\05 多对多\1、一对多的自关联.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\05 多对多\2、多对多关联查询.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\06 多对多02\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\06 多对多02\1、多对多级联新增、删除.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\07 hql01\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\07 hql01\1、hql语句的基本类容.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\08 hql02\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\09 二级缓存\0、回顾.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\09 二级缓存\1、缓存的原理.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\09 二级缓存\2、ehcache的小呆萌.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\09 二级缓存\3、抽象日志系统slf4j.mp4 E:\2018_y2_讲课\t216\17、Hibernate(8+1)\09 二级缓存\4、hibernate整合ehcache.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之jar爬取\1、通过httpclient和jsoup爬取网页,分析所有url.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之jar爬取\2、过滤无效url,迭代解析.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之jar爬取\3、利用异步线程池对爬取的性能进行优化.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之博客采集\1、通过csdn首页,提取博客地址.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之博客采集\2、将爬取到博客主题以及类容插入数据库.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之博客采集\3、利用ehcache剔除重复URL插入数据库.mp4 E:\2018_y2_讲课\t216\18、爬虫(番外篇)\网络爬虫之博客采集\4、将服务器图片本地化.mp4 E:\2018_y2_讲课\t216\19、搜索引擎lucene(番外篇)\1、lucene构建索引.mp4 E:\2018_y2_讲课\t216\19、搜索引擎lucene(番外篇)\2、lucene查询索引.mp4 E:\2018_y2_讲课\t216\19、搜索引擎lucene(番外篇)\3、lucene关键词高亮显示.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\01 ioc\0、回顾.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\01 ioc\1、spring的ioc特性.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\01 ioc\2、spring的注入方式以及类型.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\01 ioc\3、tomcat整合spring.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\02 aop\0、回顾.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\02 aop\1、前置通知、后置通知、环绕通知.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\02 aop\2、过滤通知、异常通知.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\03 ssh\1、ssh依赖导入.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\03 ssh\2、spring整合hibernate.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\03 ssh\3、spring分模块开发及案例.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\03 ssh\4、spring的biz层的用途.mp4 E:\2018_y2_讲课\t216\20、Spring(4-1)\03 ssh\5、struts整合spring.mp4 E:\2018_y2_讲课\t216\21、SVN(1)\0、回顾.mp4 E:\2018_y2_讲课\t216\21、SVN(1)\1、svn的学习.mp4 E:\2018_y2_讲课\t216\23、redis(2)\1、redis安装以及常用命令.mp4 E:\2018_y2_讲课\t216\23、redis(2)\2、Java代码操作redis.mp4 E:\2018_y2_讲课\t216\23、redis(2)\3、redis持久化和集群.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\01、mybatis入门1\0、回顾.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\01、mybatis入门1\1、mybatis的逆向工程.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\01、mybatis入门1\2、mybatis的CRUD.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\02、动态sql和分页\0、回顾.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\02、动态sql和分页\2、github的分页插件.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\02、动态sql和分页\2、动态sql续集.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\03、mybatis与spring集成\0、回顾.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\03、mybatis与spring集成\1、mybatis整合spring.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\03、mybatis与spring集成\2、spring aop使用注解处理github PageHelper.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\04、Mybatis整合Redis实现二级缓存\0、回顾.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\04、Mybatis整合Redis实现二级缓存\1、mybatis整合ehcache.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\04、Mybatis整合Redis实现二级缓存\2、mybatis整合redis.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\05、关联关系映射\0、回顾.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\05、关联关系映射\1、mybatis的一对多.mp4 E:\2018_y2_讲课\t216\24、mybatis(5)\05、关联关系映射\2、mybatis的多对多.mp4 E:\2018_y2_讲课\t216\25、springmvc(5-3)\01 springmvc入门\0、回顾.mp4 E:\2018_y2_讲课\t216\25、springmvc(5-3)\01 springmvc入门\1、springmvc入门.mp4 E:\2018_y2_讲课\t216\25、springmvc(5-3)\01 springmvc入门\2、springmvc静态资源的处理.mp4 E:\2018_y2_讲课\t216\25、springmvc(5-3)\01 springmvc入门\3、springmvc的增删查.mp4 E:\2018_y2_讲课\t216\25、springmvc(5-3)\02 国际化和文件上传\0、回顾.mp4 E:\2018_y2_讲课\t216\25、springmvc(5-3)\02 国际化和文件上传\1、springmvc的上传.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\01.shiro入门\1、shiro入门.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\01.shiro入门\2、shiro与web容器整合.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\02.shiro认证-SSM\0、回顾.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\02.shiro认证-SSM\1、shiro认证.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\02.shiro认证-SSM\2、shiro加密.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\03.shiro授权-SSM\0、回顾(2).mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\03.shiro授权-SSM\1、shiro授权.mp4 E:\2018_y2_讲课\t216\26、Shiro(2+1)\03.shiro授权-SSM\2、shiro注解式开发.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\1、springboot入门\1、springboot入门.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\1、springboot入门\2、springboot全局配置文件介绍.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\2、springboot模板\0、回顾.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\2、springboot模板\1、thymeleaf模板.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\2、springboot模板\2、freemarker模板.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\3、springboot整合mybatis\0、回顾.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\3、springboot整合mybatis\1、springboot配置数据库连接池druid.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\3、springboot整合mybatis\2、springboot整合mybatis.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\3、springboot整合mybatis\3、springboot整合pagehelper.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\4、springboot整合redis\0、回顾.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\4、springboot整合redis\1、redis的配置类.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\4、springboot整合redis\2、redis注解式开发.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\5、springboot对JPA的支持及界面版的增删改查\0、回顾.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\5、springboot对JPA的支持及界面版的增删改查\1、jpa基础.mp4 E:\2018_y2_讲课\t216\27、springboot(3+2)\5、springboot对JPA的支持及界面版的增删改查\2、springboot+bootstrap完成上传CRUD.mp4 E:\2018_y2_讲课\t216\28、quartz(2)\01.Quartz入门\0、回顾.mp4 E:\2018_y2_讲课\t216\28、quartz(2)\01.Quartz入门\1、quartz的简单使用.mp4 E:\2018_y2_讲课\t216\28、quartz(2)\01.Quartz入门\2、quartz的表达式触发器.mp4 E:\2018_y2_讲课\t216\28、quartz(2)\02.SpringBoot+Quartz+数据库存储\0、回顾.mp4 E:\2018_y2_讲课\t216\28、quartz(2)\02.SpringBoot+Quartz+数据库存储\1、quartz的环境配置.mp4 E:\2018_y2_讲课\t216\28、quartz(2)\02.SpringBoot+Quartz+数据库存储\2、quartz案例讲解.mp4 E:\2018_y2_讲课\t216\29、设计模式(3)\1、单例模式\1、设计模式之单例模式.mp4 E:\2018_y2_讲课\t216\29、设计模式(3)\2、工厂模式\1、设计模式之工厂模式.mp4 E:\2018_y2_讲课\t216\29、设计模式(3)\3、装饰器模式\1、装饰器模式.mp4
备案号:湘ICP备19000029号
Copyright © 2018-2019 javaxl晓码阁 版权所有