• 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);
        }
  • 相关阅读:
    第四周进度条
    单元测试
    第四周开发日志(psp)
    软件工程个人作业03
    第四周课堂作业——单元测试
    进度条 第三周
    开发日志
    软件工程个人作业2
    《构建之法》阅读笔记01
    第一二周进度条
  • 原文地址:https://www.cnblogs.com/huanglisong/p/13885354.html
Copyright © 2020-2023  润新知