获取文件名称列表同时获取最后修改时间

master
gongzhenkun 2 years ago
parent 1b31218d57
commit 12ef11c20e

@ -3,6 +3,7 @@ package com.ruoyi.common.utils.file;
import java.io.*; import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
@ -380,12 +381,13 @@ public class FileUtils
if (!directory.isDirectory()) { if (!directory.isDirectory()) {
throw new ServiceException(folderPath + "is not directory."); throw new ServiceException(folderPath + "is not directory.");
} }
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (directory.isDirectory()) { if (directory.isDirectory()) {
File[] fileList = directory.listFiles(); File[] fileList = directory.listFiles();
assert fileList != null; assert fileList != null;
for (File file : fileList) { for (File file : fileList) {
if (!file.isDirectory()) { if (!file.isDirectory()) {
scanFiles.add(file.getAbsolutePath()); scanFiles.add(file.getAbsolutePath() + "&" + dateFormat.format(file.lastModified()));
} }
} }
} }

Loading…
Cancel
Save