forked from TimSongCoder/LearnJavaForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDir.java
More file actions
30 lines (25 loc) · 732 Bytes
/
Copy pathDir.java
File metadata and controls
30 lines (25 loc) · 732 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
import java.io.File;
import java.io.FilenameFilter;
public class Dir{
public static void main(String[] args){
if(args.length!=2){
System.err.println("usage: java Dir dirpath extension");
return;
}
File dir = new File(args[0]);
FilenameFilter filenameFilter = new FilenameFilter(){
@Override
public boolean accept(File dir, String name){
System.out.println("accept test: dir=" + dir + ", name=" + name);
return name.endsWith(args[1]);
}
};
String[] filenames = dir.list(filenameFilter);
System.out.println();
if(filenames!=null){ // may be null because of non-directory dir argument or IO error.
for(String filename: filenames){
System.out.println(filename);
}
}
}
}