java.io.File 自己可以看看帮助,其中有一个函数 File[] listFiles(FileFilter filter)
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. 用来文件列表的简单的做法就是编写一个递归的函数来遍历目录和文件
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. 用来文件列表的简单的做法就是编写一个递归的函数来遍历目录和文件
这个参数由你确定,你想包含子目录就可以包含,全由你选择的
可以用file对象的方法获取某一个目录中的所有子目录和文件,如果是文件则创建文件流对象向文件中写入空格,否则是文件夹要再次取其子目录和所有文件
String subpath;
File newfile = new File(path); if (newfile.isDirectory()) { System.out.println(newfile.getName());
String filelist[] = newfile.list();
size = filelist.length;
for (int i = 0; i < size; i++) {
subpath = path + "\\" + filelist[i];
bianli(subpath);
}
} else if (newfile.isFile()) {
//读取文件,然后加空格,保存
} else {
System.out.println("no such file or directory");
}
}