-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirTest.java
More file actions
41 lines (32 loc) · 917 Bytes
/
Copy pathDirTest.java
File metadata and controls
41 lines (32 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package java_base;
import java.io.File;
import java.io.FilenameFilter;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DirTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
File f = new File("src\\java_base");
File[] fa = f.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(".java");
}
});
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = null;
String isDir = null;
for(File ff : fa)
{
date = sdf.format(new Date(ff.lastModified()));
isDir= ff.isDirectory()?"<dir>":":";
System.out.printf("%s\t\t%d\t%s\t%s\n", ff.getName(), ff.length(), isDir, date);
System.out.println(isDir);
}
}
}
/*
*
*出现 ? 就是 if else 的意思File.listFiles() 查看目录 可以重写方法进行过滤
*/