标签:col drive ast lse 文件夹 folder amp null add
/**
* Getting files from Folder(Time Sorting by Modify time)
* @param path
* @return
*/
private List<File> getFileSort(String path) {
List<File> list = getFiles(path, new ArrayList<File>());
if (list != null && list.size() > 0) {
Collections.sort(list, new Comparator<File>() {
public int compare(File file, File newFile) {
if (file.lastModified() < newFile.lastModified()) {
return 1;
} else if (file.lastModified() == newFile.lastModified()) {
return 0;
} else {
return -1;
}
}
});
}
return list;
}
/**
* Get all the file from folders(img/{drivesid})
*
* @param realpath
* @param files
* @return
*/
private List<File> getFiles(String realpath, List<File> files) {
File realFile = new File(realpath);
if (realFile.isDirectory()) {
File[] subfiles = realFile.listFiles();
for (File file : subfiles) {
if (file.isDirectory()) {
getFiles(file.getAbsolutePath(), files);
} else {
files.add(file);
}
}
}
return files;
}
标签:col drive ast lse 文件夹 folder amp null add
原文地址:https://www.cnblogs.com/sunnykwan/p/12306821.html