zoukankan      html  css  js  c++  java
  • java 删除所有早于N天的文件(递归选项,它遍历子文件夹)

    public static void recursiveDeleteFilesOlderThanNDays(int days, String dirPath) throws IOException {
        long cutOff = System.currentTimeMillis() - (days * 24 * 60 * 60 * 1000);
        Files.list(Paths.get(dirPath))
        .forEach(path -> {
            if (Files.isDirectory(path)) {
                try {
                    recursiveDeleteFilesOlderThanNDays(days, path.toString());
                } catch (IOException e) {
                    // log here and move on
                }
            } else {
                try {
                    if (Files.getLastModifiedTime(path).to(TimeUnit.MILLISECONDS) < cutOff) {
                        Files.delete(path);
                    }
                } catch (IOException ex) {
                    // log here and move on
                }
            }
        });
    }
    
  • 相关阅读:
    RIGHT JOIN 关键字
    LEFT JOIN 关键字
    INNER JOIN 关键字
    连接(JOIN)
    别名
    BETWEEN 操作符
    IN 操作符
    通配符
    LIKE 操作符
    LIMIT 子句
  • 原文地址:https://www.cnblogs.com/interdrp/p/15640921.html
Copyright © 2011-2022 走看看