最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java删除指定目录下指定格式文件的方法
时间:2018-08-23 编辑:猪哥 来源:一聚教程网
正在看疯狂java讲义这本书,发现源码中有我不需要的class文件,想批量把它删除
代码如下:
import java.io.File; public class Main { static int count = 0; public static void main(String[] args) { //路径 String path="/media/lcy/Data/Workspaces/java/crazyJava"; String geshi=".class"; refreshFileList(path,geshi); System.out.println("共删除了:" + count + "个文件!"); } public static void refreshFileList(String strPath,String geshi) { File dir = new File(strPath); File[] files = dir.listFiles(); if (files == null) { System.out.println("该目录下没有任何一个文件!"); return; } for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { refreshFileList(files[i].getAbsolutePath(),geshi); }else { String strFileName = files[i].getAbsolutePath().toLowerCase(); if(strFileName.endsWith(geshi)){ System.out.println("正在删除:" + strFileName); files[i].delete(); count++; } } } } }
-
下一个: SSH原理及两种登录方法图文详解
相关文章
- SpringBoot自定义bean绑定解析 10-24
- Javaweb工程运行报错HTTP Status 404解决教程 10-20
- JAVA获取jvm和操作系统相关信息方法 10-20
- BeanFactory和FactoryBean的区别讲解 10-20
- 微信小程序的宿主环境实现教程 10-10
- dispatchEvent解决重叠元素响应事件教程 10-10