1.[代码][Java]代码
import java.util.*;
import java.io.*;
public class Filewenjianliebiao
{
public static void main(String []args)
{
File dir=new File("d:\\java Gongzuo");
List list=new ArrayList();
fileToList(dir,list);
File file=new File("d:\\javaList.txt");
writeToFile(list,file.toString());
}
public static void fileToList(File dir,List list)
{
File[] files=dir.listFiles();
for(File f:files)
{
if(f.isDirectory())
fileToList(f,list);
else
{
if(f.getName().endsWith(".java"))
list.add(f);
}
}
}
public static void writeToFile(List list,String javaListFile)
{
BufferedWriter bufw=null;
try
{
bufw=new BufferedWriter(new FileWriter(javaListFile));
for(File f:list)
{
String path=f.getAbsolutePath();
bufw.write(path);
bufw.newLine();
bufw.flush();
}
}
catch(IOException e)
{
throw new RuntimeException("----不知道怎么处理见谅----");
}
finally
{
try
{
if(bufw!=null)
bufw.close();
}
catch(IOException e)
{
throw new RuntimeException("......");
}
}
}
}