package lesson0923;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
public class Exercise2 {
public static void main(String[] args) throws IOException {
String path = "./files";
for(int i=1;i<=100;i++) {
File file = new File(path,"文件名"+fileZero(i+"",3)+".txt");
if(!file.exists()) {
file.createNewFile();
}
}
File file1 = new File(path);
File[] files = file1.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.getName().matches("文件名\\d{2}[13579]\\.txt");
}
});
for(File f:files) {
f.delete();
}
System.out.println("总数是:"+files.length);
}
//不够长度就在左边补0
public static String fileZero(String s,int l) {
//把字符串长度计算好
int count = l-s.length();
for(int i=0;i<count;i++) {
s = "0"+s;
}
return s;
}
}
920-2
最新推荐文章于 2023-11-10 23:01:55 发布