package com.itheima;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
public class Test32 {
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
try {
str=br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
File fi = new File(str);
if(!fi.exists()&&fi.isDirectory())
try {
throw new FileNotFoundException();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
getFile(fi);
}
private static void getFile(File fi) {
System.out.println(fi.getName());
File[] files = fi.listFiles();
for(File file:files){
if(file.isDirectory())
getFile(file);
else
System.out.println(file.getName());
System.out.println();
}
}
}
|
|