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++;
}
}
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。