package csdn20220824;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Test {
private final static String REG = "^.*\\d{14}.*$";
public static void main(String[] args) {
File file = new File("D://test/");
List<Long> list = new ArrayList<>();
File[] files = file.listFiles();
for (File f : files) {
if (f.getName().matches(REG)) {
String s = numberStr(f.getName());
if (s.length() == 14) {
Long l = Long.parseLong(s);
list.add(l);
}
}
}
Long oldStr = list.stream().min(Long::compareTo).get();
for (File f : files) {
if (f.getName().contains(oldStr + "")) {
System.out.println(f.getName());
}
}
}
public static String numberStr(String str){
int max = 0,count = 0,end = 0;
for (int i = 0; i < str.length(); i++) {
if(str.charAt(i) >= '0' && str.charAt(i) <= '9'){
count++;
if(max < count){
max = count;
end = i;
}
}else{
count = 0;
}
}
return str.substring(end - max + 1,end + 1);
}
}