/*
列出指定目录下的文件,文件夹,包括子目录下面的文件
*/
import java.io.*;
class Mulushuchu
{
public static void main(String[] args) throws Exception
{
File dir=new File("d:");
StringBuilder sb=new StringBuilder();
//System.out.println(sb.toString());
FileWriter w=new FileWriter("3.txt");
BufferedWriter fw=new BufferedWriter(w);
show(dir,fw);
fw.close();
}
public static void show(File dir,BufferedWriter fw)throws Exception
{
//System.out.println(dir);
File[] arr=dir.listFiles();
for(File f:arr)
{
if(!f.isHidden()&&f.isDirectory())
{
show(f,fw);//递归
}
else
{
fw.write(f.getPath());
fw.newLine();
fw.flush();
}
}
}
}
|