`
wenjinglian
  • 浏览: 807783 次
  • 性别: Icon_minigender_1
  • 来自: 株洲->深圳
社区版块
存档分类
最新评论

java递归遍历文件

    博客分类:
  • JAVA
阅读更多

 this recursive function

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);
      }
    }
  }
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics