在控制台列出桌面文件及文件大小,按修改时间排序

 1 package com.laurdawn;
 2 
 3 import java.io.File;
 4 import java.util.Date;
 5 
 6 public class Test {
 7 
 8     public static void main(String[] args) {
 9         // TODO Auto-generated method stub
10         WorkSpace();
11     }
12 
13     public static void WorkSpace() {
14         File f = new File("C:/Users/Administrator/Desktop/");
15         File[] array = f.listFiles();
16         for (int j = 1; j < array.length; j++) {
17             for (int i = 1; i < array.length; i++) {
18                 Date x = new Date(array[i].lastModified());
19                 Date y = new Date(array[i - 1].lastModified());
20                 if (x.after(y)) {
21                     File temp = array[i - 1];
22                     array[i - 1] = array[i];
23                     array[i] = temp;
24                 }
25             }
26         }
27         for (File n : array) {
28             Date d = new Date(n.lastModified());
29             System.out.print("文件名:" + n.getName());
30             System.out.print(";    文件大小:" + n.length() + "字节;");
31             System.out.println("    最近修改日期:" + d);
32         }
33     }
34 
35 }

 

posted @ 2016-07-01 09:33  laurdawn  阅读(408)  评论(0编辑  收藏  举报