搜索E盘的说有jpg图片
import java.io.*;
public class SearchPicture{
static int j=0;
static FileWriter w = null;
public static void main(String args[]){
try{FileWriter FW = new FileWriter("d:\\picture.txt");
FW.write("");
FW.close();
}catch(IOException a){a.printStackTrace();}
File f = new File("e:\");
tree(f);
System.out.println("总共"+j+"张图片");
try{FileWriter FW = new FileWriter("d:\\picture.txt",true);
FW.write("总共"+j+"张图片");
FW.close();
}catch(IOException a){a.printStackTrace();}
}
public static void tree(File f){
String[] s = null;
File[] trees = null;
trees = f.listFiles();
for(int i=0;i<trees.length;i++)
{
if(trees[i].isDirectory()&&trees[i].listFiles()!=null){
tree(trees[i]);
}
s = trees[i].getName().split("\\.");
if(s[s.length-1].equals("jpg")) {
System.out.println(trees[i].getAbsolutePath());
try{
w = new FileWriter("d:\\picture.txt",true);
w.write(trees[i].getAbsolutePath());
w.write(13);
w.write(10);
//w.write("\n\r");
w.flush();
w.close();
}catch(IOException e){
e.printStackTrace();
}
j++;
}
}
}
}