本帖最后由 天方地圆 于 2014-3-24 09:35 编辑
- /*
- 创建java文件列表。
- */
- import java.io.*;
- import java.util.*;
- class JavaFileList
- {
- public static void main(String[] args) throws IOException
- {
- File dir = new File("f:\\java0217");
- List<File> list = new ArrayList<File>();
- fileToList(dir,list);
- File file = new File(dir,"javalist.txt");
- witeToFile(list,file.toString());
- }
- public static void fileToList(File dir,List<File> list)
- {
- File[] files = dir.listFiles();
- for (File file : files)
- {
- if(file.isDirectory())
- fileToList(file,list);
- else
- {
- if(file.getName().endsWith(".java"));
- list.add(file);
- }
- }
- }
- public static void witeToFile(List<File> list,String javaListFile) throws IOException
- {
- 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 e;
- }
- finally
- {
- try
- {
- if(bufw!=null)
- bufw.close();
- }
- catch (IOException e)
- {
- throw e;
- }
- }
- }
- }
复制代码 出来的结果确实所有格式都打出来了?疑惑。。 |
|