- package com.itcast.day4;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- public class JavaFileList {
- /**
- * @param args
- */
- public static void main(String[] args) {
-
- File dir = new File("F:/java/java0903");
-
- List<File> list = new ArrayList<File>();
- listToFile(dir,list);
-
- Iterator<File> it = list.iterator();
- while(it.hasNext()) {
- System.out.println(it.next());
- }
- }
-
- public static void listToFile(File dir,List<File> list) {
-
- File[] files = dir.listFiles();
-
- for(File file : files) {
- if(file.isDirectory()) {
- listToFile(file,list);
- } else {
- if(file.getName().endsWith(".java")) {
- list.add(file);
- }
- }
- }
- }
- }
复制代码 |
|