zoukankan      html  css  js  c++  java
  • 删除临时文件

    遍历指定目录下(包括其子目录)的所有文件,并删除以 lastUpdated 结尾的文件
    package com.chinamobile.cmss.vrms.controller;
    
    import java.io.File;
    import java.io.IOException;
    
    public class Test {
    
            /**
             * 遍历指定目录下(包括其子目录)的所有文件,并删除以 lastUpdated 结尾的文件
             * @param dir 目录的位置 path
             * @throws IOException
             */
            public static void listDirectory(File dir) throws IOException {
                if (!dir.exists()) {
                    throw new IllegalArgumentException("目录:" + dir + "不存在.");
                }
                if (!dir.isDirectory()) {
                    throw new IllegalArgumentException(dir + " 不是目录。");
                }
                File[] files = dir.listFiles();
                if (files != null && files.length > 0) {
                    for (File file : files) {
                        if (file.isDirectory())
                            //递归
                            listDirectory(file);
                        else{ // 删除以 lastUpdated 结尾的文件
                            String fileName = file.getName();
                            boolean isLastupdated = fileName.toLowerCase().endsWith("lastupdated");
                            if (isLastupdated){
                                boolean is_delete = file.delete();
                                System.out.println("删除的文件名 => " + file.getName() + "  || 是否删除成功? ==> " + is_delete);
                            }
                        }
                    }
                }
            }
    
            public static void main(String[] args) throws IOException {
                // 指定maven的本地仓库
                listDirectory(new File("D:\Idea\repository"));
            }
        }
  • 相关阅读:
    CVE-2014-6271 Shellshock 破壳漏洞 复现
    0ctf-ezdoor-复现分析
    phpinfo中敏感信息记录
    未授权访问总结学习
    关于PHP内部类的一些总结学习
    PHP反序列化总结
    SSRF和XSS-filter_var(), preg_match() 和 parse_url()绕过学习
    Java14:你需要知道的新特性
    结构型设计模式
    项目总结
  • 原文地址:https://www.cnblogs.com/wangjinnan97/p/14037347.html
Copyright © 2011-2022 走看看