Display all files and folders in the entire windows folder

Exercise

Request to display all files and folders in the entire windows folder

  • If it is a file, display the file name size
  • If it is a folder, it shows that the absolute path is a folder
public class Test {
    
     
	public static void main(String[] args) {
    
     
		File ff = new File("c:/windows"); 
		showFile(ff); 
	}
	public static void showFile(File target) {
    
     
		if(target!=null) {
    
     
			if(target.isFile()) {
    
     															
				System.out.println("\t"+target.getName()+"\t"+target.length()); 
			}else if(target.isDirectory()) {
    
     	
				System.out.println(target.getAbsolutePath()+"是文件夹!"); 
				File[] fs=target.listFiles(); 	
				if(fs!=null && fs.length>0) {
    
     
					for(File tmp:fs) showFile(tmp); 
				} 
			} 
		} 
	} 
}

Guess you like

Origin blog.csdn.net/qq_43480434/article/details/113136040