java 文件处理代码

时间:2019-03-08 16:49:41
【文件属性】:
文件名称:java 文件处理代码
文件大小:1KB
文件格式:TXT
更新时间:2019-03-08 16:49:41
文件 日期 排序 java 遍历 实体文件 排序方法 import java.io.File; import java.util.Date; import java.util.Iterator; import java.util.Set; import java.util.TreeMap; public class TT { private static final long serialVersionUID = 7025768684443110109L; public static void main(String[] args) { new TT().getFilePathName(); } public String getFilePathName() { TreeMap tm = new TreeMap(); File file = new File("C:\\z"); File subFile[] = file.listFiles(); int fileNum = subFile.length; for (int i = 0; i < fileNum; i++) { Long tempLong = new Long(subFile[i].lastModified()); tm.put(tempLong, subFile[i]); } System.out.println("按时间从前到后排序--->"); System.out.println("最早的一个文件的路径-->"+tm.get(tm.firstKey()).getPath()+tm.firstKey()); System.out.println("最近的一个文件的路径-->"+tm.get(tm.lastKey()).getPath()+tm.lastKey()); Set set = tm.keySet(); Iterator it = set.iterator(); while (it.hasNext()) { Object key = it.next(); Object objValue = tm.get(key); File tempFile = (File) objValue; Date date=new Date((Long)key); System.out.println(tempFile.getPath() + "\t"+date); } return null; } }

网友评论