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
42
43
44
|
package
com.example.s_27;
import
java.io.File;
import
android.app.Activity;
import
android.os.Bundle;
public
class
MainActivity
extends
Activity {
public
static
int
i =
0
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new
Thread() {
public
void
run() {
String path =
"/sdcard/androidesk/"
;
getFiles(path);
System.out.println(path +
" 文件夹下面共有 "
+ i +
" 张图片文件"
);
};
}.start();
}
private
void
getFiles(String string) {
// TODO Auto-generated method stub
File file =
new
File(string);
File[] files = file.listFiles();
for
(
int
j =
0
; j < files.length; j++) {
String name = files[j].getName();
if
(files[j].isDirectory()) {
String dirPath = files[j].toString().toLowerCase();
System.out.println(dirPath);
getFiles(dirPath +
"/"
);
}
else
if
(files[j].isFile() & name.endsWith(
".jpg"
) || name.endsWith(
".png"
) || name.endsWith(
".bmp"
) || name.endsWith(
".gif"
) || name.endsWith(
".jpeg"
)) {
System.out.println(
"FileName==="
+ files[j].getName());
i++;
}
}
}
}
清单文件 manifest 节点下面添加 读取权限
|