package www.itcast.listFile;
import java.io.*;
public class ListFile {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader bufr = new BufferedReader(new InputStreamReader(
System.in));
String line = null;
while ((line = bufr.readLine()) != null) {
File file = new File(line);
if (file.exists()) {
listFiles(file);
}
}
}
private static void listFiles(File dir) {
// TODO Auto-generated method stub
System.out.println("目录:" + dir.getPath());
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
listFiles(files[i]);
} else {
System.out.println("文件:" + files[i].getPath());
}
}
}
}
|
|