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);
}
}
}
}
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);
}
}
}
}
相关文章推荐
- java 如何递归遍历一个文件夹下的所有文件
- 基于Java Socket的文件UpLoad代码(完美版)-用递归解决java的目录树遍历
- java 遍历递归操作(改名) 文件/文件夹
- JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
- Java递归遍历删除拷贝文件以及获取文件夹大小
- JAVA 遍历文件夹下的所有文件(递归调用)
- java:利用递归遍历整个文件夹并写入文件
- java递归实现文件夹文件的遍历输出
- java题-如何递归遍历一个文件夹下的所有文件
- 基于Java Socket的文件UpLoad代码(完美版)-用递归解决java的目录树遍历
- 遍历文件夹找出所有.java文件(递归)
- java 如何递归遍历一个文件夹下的所有文件
- JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
- java基础知识回顾之javaIO类--File类应用:递归深度遍历文件
- java基础:递归应用---遍历文件目录
- 基于Java Socket的文件UpLoad代码(完美版)-用递归解决java的目录树遍历
- JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
- java遍历文件目录(采用递归)
- Java递归之遍历及删除文件夹文件
- 基于Java Socket的文件UpLoad代码(完美版)-用递归解决java的目录树遍历