디렉토리에있는 파일에서 내용을 읽는 방법이 있습니다. 기능상의 이유 때문에 가장 오래된 파일 (lastmodified 속성으로 표시)부터 시작하여 최신 파일로 끝내야합니다.디렉토리의 파일을 java로 날짜별로 정렬하는 방법은 무엇입니까?
이 내가 파일을 열고 읽는 방법 코드는 다음과 같습니다
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.matches("access_log.*");
}
};
File folder = new File("/home/myfiles");
File[] listOfFiles = folder.listFiles(filter);
for (int i = 0; i < listOfFiles.length; i++) {
String sFileName = listOfFiles[i].getName();
File accessLogFile = new File(aLog.getPath(), sFileName);
long time=accessLogFile.lastModified();
// do something with the file
}
아무도 내가 빨리 날짜로 파일 내 목록을 정렬 할 수있는 방법을 해결 했습니까?
질문에 대한 답변이 http://stackoverflow.com/questions/203030/best-way-to-list-files-in-java-sorted-by-date-modified에 포함되어 있습니까? – sverre
FileUtils.dirListByAscendingDate를 사용해 보셨습니까? http://www.rgagnon.com/javadetails/java-0606.html – excanoe
로그 파일에 관심이있는 것 같습니다. 이것들은 종종 파일 이름에 의한 어휘 정렬 또한 시간에 따라 정렬되는 방식으로 명명됩니다. –