• java查找最新文件


        public static File findLatesFile(final String path, final String keyword) {
            return findLatesDirectory(path, keyword, false);
        }
    
        public static File findLatesDirectory(final String path, final String keyword) {
            return findLatesDirectory(path, keyword, true);
        }
    
        public static File findLatesDirectory(final String path, final String keyword, final boolean isDirectory) {
            if (StringUtils.isBlank(path)) {
                throw new RuntimeException("Path is invalid.");
            }
            File srcFolder = new File(path);
            if (srcFolder.isFile()) {
                throw new RuntimeException("Path is not a folder.");
            }
            File[] files = null;
            if (StringUtils.isNotBlank(keyword)) {
                files = srcFolder.listFiles(new FileFilter() { // search files for
                                                                // keyword
                    public boolean accept(File pathname) {
                        if (isDirectory) {
                            return pathname.getName().contains(keyword);
                        }
                        return pathname.isFile() && pathname.getName().contains(keyword);
                    }
                });
            } else {
                files = srcFolder.listFiles();
            }
            if (!CollectionUtils.isEmpty(Arrays.asList(files))) {
                Arrays.sort(files, Collections.reverseOrder());
                return files[0];
            }
    
            throw new RuntimeException("Directory is empty.  " + path);
        }
  • 相关阅读:
    1.计算机初识
    re模块前瞻后顾 快速
    getattr 对类使用
    sklearn iris快速
    numpy c_
    sorted函数 字典按值倒序 实现
    logging快速入门
    configparser快速应用
    reduce 和 map 函数
    一个简单的类继承
  • 原文地址:https://www.cnblogs.com/huanglisong/p/13885354.html
Copyright © 2020-2023  润新知