|
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 |
package
com.zsh.test;import
java.io.File;import
java.io.FileFilter;public
class Test implements
FileFilter { /** * @param args * @author Ben Zeph */ String condition = ""; public
Test(String condition) { this.condition = condition; } @Override public
boolean accept(File pathname) { String filename = pathname.getName(); if
(filename.lastIndexOf(condition) != -1) { return
true; } else return
false; } public
static void
main(String[] args) { File[] files = root.listFiles(new
Test(".txt")); if
(files.length != 0) for
(int
i = 0; i < files.length; i++) System.out.println(files[i]); }} |
如何列出C盘下所有的txt文件,布布扣,bubuko.com
原文:http://www.cnblogs.com/zhongshenghua/p/3582831.html