最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java删除指定目录下指定格式文件的方法
时间:2022-06-29 00:59:11 编辑:袖梨 来源:一聚教程网
正在看疯狂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++;
}
}
}
}
}
相关文章
- 12306车票开售即候补-揭秘12306车票秒变候补真相 02-07
- steam官网网页版入口-steam网页版快捷登录入口 02-07
- 知乎网页版入口-知乎网页版免费登录地址 02-07
- poki免费游戏大全-poki免下载即玩入口 02-07
- 抖音网页版入口在哪-抖音电脑版官网一键直达 02-07
- 126企业邮箱快捷登录-邮箱126免费版极速入口 02-07