本帖最后由 罗广伟 于 2013-7-9 22:49 编辑
- <div class="blockcode"><blockquote>import java.io.*;
- import java.util.*;
- public class JavaFileList
- {
- public static void main(String[] args)
- {
- File dir=new File("g:\\android");
- List<File> list=new ArrayList<File>();
- fileToList(dir,list);
- File file=new File("g:\\android\\javalist.txt");
- writerToFile(list,file.toString());
- }
- public static void fileToList(File dir,List<File> list)
- {
- File[] file=dir.listFiles();
- for(File f:file)
- {
- if(f.isDirectory())
- fileToList(f,list);
- else
- {
- if(f.getName().endsWith(".avi"))
- list.add(f);
- }
-
- }
- }
- public static void writerToFile(List<File> 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)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- if(bufw!=null)
- bufw.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
复制代码 问题位置20天-10在×××出为什么构造函数要传递String javaListFile而不是传递一个File对象,这样做有什么好处吗? |