zoukankan      html  css  js  c++  java
  • java输入一个文件夹,查找出所有的文件列表

    /*
     *java list file demo
     @author:luowen
     @time:2013-10-25
     * */
    
    import java.io.*;
    import java.util.*;
    
    class FileToList
    {
        public static void main(String[] args)
        {
               File f = new File("d:/") ;
               List<File> list = new ArrayList<File>();
               toList(f,list);
               toFile(list);
        }
    
        public static void toList(File f,List<File> list)
        {
            File[] files = f.listFiles();
            for(File file : files)
            {
                if(file.isDirectory())
                {
                    toList(file,list);
                }
                else
                {
                    if(file.getName().endsWith(".php"))
                    list.add(file);
                }
            }
        }
        public static void toFile(List<File> list)
        {
           BufferedWriter bufw  = null;
           try
           {
               bufw = new BufferedWriter(new FileWriter("d:/phpList.txt")) ;
               for(File ls : list)
               {
                    bufw.write(ls.getAbsolutePath());
                    bufw.newLine();
                    bufw.flush();
               }
    
           }
           catch(IOException e)
           {
                 throw new RuntimeException("write error");
           }
           finally
           {
               try
               {
                 if(bufw != null)
                    bufw.close();
               }
               catch(IOException e)
               {
                throw new RuntimeException("write error");
               }
           }
    
        }
    }
  • 相关阅读:
    Java1:Chapter2
    Java1:Chapter1
    Java1:Chapter11
    Java1:Chapter8
    Java1:Chapter6
    Android day 03
    Android day02
    Android day01
    二进制文件的读写
    字符流
  • 原文地址:https://www.cnblogs.com/luowen/p/3388762.html
Copyright © 2011-2022 走看看