為做一個文件管理系統所實現的一個很粗糙的小例子
下面是源代碼
import java
import java
/**
* Created by IntelliJ IDEA
* <b>User</b>: leizhimin<br>
* <b>Date</b>:
* <b>Note</b>: 文件排序
*/
public class FileComparator implements Comparator<File> {
public int compare(File o
if (o
else if(o
else if(!o
else return pareTo(o
}
}
import java
import java
import java
import java
import java
import java
/**
* Created by IntelliJ IDEA
* <b>User</b>: leizhimin<br>
* <b>Date</b>:
* <b>Note</b>: 模擬dir測試的例程
*/
public class TestFile {
public static DateFormat df = new SimpleDateFormat(
int nl =
public static void main(String args[]) {
test();
}
public static void test() {
System
File file = new File(
// file
// System
// System
// System
// System
FileComparator fc = new FileComparator();
File[] lf = file
Arrays
for (File f : lf) {
String dataStr = df
if (f
System
} else {
System
}
System
}
}
//格式化函數
public static String getFormatString(String s) {
int nb =
StringBuilder sb = new StringBuilder();
if (nb >
for (int n =
sb = sb
}
}
return sb
}
}
運行效果
blog的在線編輯器顯示好像有點問題
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19733.html