java根据文件创建时间排序,然后修改文件名称

复制代码
public void rankFileByTime() {
        String s = "文件夹路径";
        File file = new File(s);
        File[] files = file.listFiles();
        Arrays.asList(files).forEach(x -> System.out.println(x.getName()));
        Arrays.sort(files, Comparator.comparingLong(File::lastModified));
        System.out.println("======================");
        Arrays.asList(files).forEach(x -> System.out.println(x.getName()));
        int count;
        for (int i = 0; i < files.length; i++) {
            count = i+1;
            files[i].renameTo(new File(s + File.separator + count + ".jpg"));
        }
    }
复制代码

 

posted @   不要西红柿  阅读(192)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示