2025-05-23

this recursive function



Java代碼 
public class Test {  
 
    public static void main(String[] args) throws IOException {  
        File file = new File(“E:\plan”);  
        Test.recursive(file);  
    }  
      
    public static void  recursive(File file)  
    throws IOException {  
    // do not try to index files that cannot be read  
    if (file.canRead()) {  
      if (file.isDirectory()) {  
        String[] files = file.list();  
        // an IO error could occur  
        if (files != null) {  
          for (int i = 0; i < files.length; i++) {  
              recursive(new File(file, files[i]));  
          }  
        }  
      } else {  
        System.out.println(“adding ” + file);  
      }  
    }  
  }  

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *