Dir filter how to set ?
Now. Output as below, I want just list out *.java , how to using filter
?
1 i = 60, 2003-01-22 23:01:02, .\testing\template.java
1 i = 61, 2003-01-12 01:38:02, .\testing\Triangle.class
1 i = 62, 2003-01-21 22:32:28, .\testing\user.home
1 i = 63, 2003-01-17 20:27:54, .\testing\Vehicle.class
0 i = 100, 2006-08-12 00:58:44, .\testing.class
0 i = 101, 2005-07-31 00:27:58, .\testing.java
0 i = 102, 2005-07-22 08:50:19, .\Thread
1 i = 0, 2005-07-21 22:59:16, .\Thread\MaskingThread.class
1 i = 1, 2003-02-14 12:01:16, .\Thread\MaskingThread.java
1 i = 2, 2003-03-01 23:18:20, .\Thread\ThreadDemo.java
1 i = 3, 2005-10-04 10:48:10, .\Thread\WithThread.java
0 i = 103, 2005-08-04 10:42:30, .\unicode
import java.io.*;
import java.util.*;
import java.text.*; // For DateFormat
public class Dir {
static int indentLevel = - 1;
Dir (String path) {
listPath (new File (path));
}
void listPath (File path) {
File files []; //List of files in a Directory
indentLevel++; // Going Down...
// Create list of files in this dir
files = path.listFiles();
// Sort with help of Collections API
Arrays.sort(files);
for (int i= 0, n=files.length ; i < n ; i++) {
for (int indent = 0 ; indent <
indentLevel; indent++) {
System.out.print(" ");
}
// DateFormat df = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss.SSS");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
Date date = new Date(files[i].lastModified());
//String s =
df.getDateInstance(DateFormat.MEDIUM).format(date);
String s = df.format(date);
System.out.println(indentLevel + " i = " + i + ", " +
s + ", " +
files[i].toString());
if (files[i].isDirectory()) {
listPath(files[i]);
}
}
indentLevel--; // and going up
}
// Main
public static void main (String args[]) {
new Dir(args[0]);
}
}
Reply =BB