java代码删除Maven仓库中下载错误文件

作用同上

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Demo03 {
    private static Pattern pattern = Pattern.compile(".lastUpdated");

    public static void main(String[] args) {
//         获取所要删除的目录
//        Scanner scanner = new Scanner(System.in);
//        maven仓库位置
        String cataLog = "D:\\Maven\\apache-maven-3.6.1-bin\\MavenRepository";
        File cataLogObject = new File(cataLog);
        if (!cataLogObject.exists()) {
            System.out.println("未发现目录");
            System.exit(1);
        }
        System.out.println("存在该路径");
        isDirectory(cataLogObject);
    }

    
    private static void isDirectory(File file) {

        if (file.isDirectory()) {
            File[] ne = file.listFiles();
            for (int i = 0; i < ne.length; i++) {
                isDirectory(ne[i]);
            }
            File[] nextNe = file.listFiles();
            if (nextNe.length < 1) {
                file.delete();
            }
        } else {
            Matcher matcher = pattern.matcher(file.getName());
            if (matcher.find()) {
                System.out.println("这是一个File==>" + file.getName());
                file.delete();
            }
        }
    }

}

 

你可能感兴趣的:(java,maven,java,原创)