1
/**
2
* 列出某文件夾及其子文件夾下面的文件,并可根據擴展名過濾
3
*
4
* @param path
5
*/
6
public static void list(File path)
7
{
8
if (!path.exists())
9
{
10
System.out.println("文件名稱不存在!");
11
}
12
else
13
{
14
if (path.isFile())
15
{
16
if (path.getName().toLowerCase().endsWith(".pdf")
17
|| path.getName().toLowerCase().endsWith(".doc")
18
|| path.getName().toLowerCase().endsWith(".html")
19
|| path.getName().toLowerCase().endsWith(".htm"))
20
{
21
System.out.println(path);
22
System.out.println(path.getName());
23
}
24
}
25
else
26
{
27
File[] files = path.listFiles();
28
for (int i = 0; i < files.length; i++)
29
{
30
list(files[i]);
31
}
32
}
33
}
34
}

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
