Comprehensive case: List all files in the specified directory
Now it is up to the developer to set a directory path arbitrarily. Then list all the file information under this directory, including all files in the subdirectory.
Implementation class:
public static void listDir(File file){
if(file.isDirectory()){ //是一个目录
File[] results = file.listFiles(); //列出目录中的全部内容
if(results != null){
for(int x = 0;x<results.length;x++){
listDir(results[x]); //继续依次判断
}
}
}else{ //不是一个目录
System.out.println(file);
}
}
Main method:
public static void main(String[] args) throws IOException {
File file = new File("E:"+File.separator); //File.separator表示分隔符
listDir(file);
}
If the path is now a delete operation, then the path is completely deleted