天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
JavaIO利用迭代读取文件夹所有目录及文件

 

 1import java.io.File;
 2import java.util.ArrayList;
 3
 4public class ReadFile {
 5 public static void main(String args[]) {
 6  String dir = "D:\\xxx";
 7
 8  ArrayList a = getFiles(dir);
 9  for (int i = 0; i < a.size(); i++{
10   File file = (File) a.get(i);
11  }

12 }

13
14 public static ArrayList getFiles(String aDir) {
15  ArrayList files = new ArrayList();
16  File dirx = new File(aDir);
17  File[] dirFilesx = dirx.listFiles();
18
19  for (int k = 0; k < dirFilesx.length; k++{
20   System.out.print("|");
21   File file = dirFilesx[k];
22   String fileName = file.getName();
23   System.out.println("-" + fileName);
24   if (file.isDirectory()) {
25    String dirx1 = aDir + "\\" + fileName;
26    getFiles(dirx1);
27   }

28   files.add(file);
29  }

30  return files;
31
32 }

33
34}

35
36

posted on 2005-11-07 18:08 bluesky 阅读(993) 评论(0)  编辑  收藏 所属分类: 基础知识


只有注册用户登录后才能发表评论。


网站导航: