- package 遍历E盘;
- //遍历E盘下的文件夹目录
- import java.io.*;
- public class IOliu {
- static BufferedWriter xie = null;
- public static void main(String[] args) throws IOException {
- File fe = new File("E://");
- xie = new BufferedWriter(new FileWriter("E:\\KuGou\\a.txt"));
- show(fe, 0);
-
- xie.flush();
- xie.close();
- }
- public static String ggt(int le) {
- StringBuilder sb = new StringBuilder();
- for (int x = 0; x < le; x++) {
- sb.append(" ");
- }
- return sb.toString();
- }
- public static void show(File f, int le) throws IOException {
- // TODO Auto-generated method stub
- System.out.println(ggt(le) + f);
- le++;
- xie.write(ggt(le) + f.toString());
- xie.newLine();
- File[] files = f.listFiles();
- for (int x = 0; x < files.length; x++) {
- if (files[x].isDirectory()) {
- show(files[x], le);
- } else {
- System.out.println(ggt(le) + files[x]);
- xie.write(ggt(le) + files[x]);
- xie.newLine();
- }
- }
- }
- }
复制代码
|
|