您的位置:首页 > 编程语言 > Java开发

java递归遍历文件

2013-05-01 09:32 239 查看
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);

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: