File §1

The Class of File, it can be seen as one document, also can be seen as list of documents.

File  f = new File(String url);

f may be a document,also might be a directory.

 

Example : use  recursive algorithmt  to gain the all files in a absolute path.

 public class Demo1 {
 
    public static void main(String[] args) {
  
        File f = new File("C:/Users/caich5/Desktop/Chris");
  
        recussion(f);
 }

public static void recussion(File file){
  
    if(file.isDirectory()){
   
        File[] files = file.listFiles();
   
        for (File everyFile : files) {
    
            if(everyFile.isFile()){
     
               System.out.println(everyFile.getName());
             }

            else{

               recussion(everyFile);
             }
        }
     }
  }

 

posted @ 2018-03-02 15:11  Chris,Cai  阅读(157)  评论(0编辑  收藏  举报