From f13cccf5a6f3c98d76dab5fec9deb4e8db997bbb Mon Sep 17 00:00:00 2001 From: kl Date: Fri, 24 Mar 2023 13:41:19 +0800 Subject: [PATCH] Get the file list sorted in descending order --- .../main/java/cn/keking/web/controller/FileController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/cn/keking/web/controller/FileController.java b/server/src/main/java/cn/keking/web/controller/FileController.java index 669782df..3783da00 100644 --- a/server/src/main/java/cn/keking/web/controller/FileController.java +++ b/server/src/main/java/cn/keking/web/controller/FileController.java @@ -119,7 +119,9 @@ public class FileController { List> list = new ArrayList<>(); File file = new File(fileDir + demoPath); if (file.exists()) { - Arrays.stream(Objects.requireNonNull(file.listFiles())).forEach(file1 -> { + File[] files = Objects.requireNonNull(file.listFiles()); + Arrays.sort(files, (f1, f2) -> Long.compare(f2.lastModified(), f1.lastModified())); + Arrays.stream(files).forEach(file1 -> { Map fileName = new HashMap<>(); fileName.put("fileName", demoDir + "/" + file1.getName()); list.add(fileName);