首页 > 代码库 > File List

File List

 1 public class Question1 { 2  3     public static void main(String[] args) { 4         String dir=""; 5         if(args.length!=1) 6         { 7             System.out.println("Please Enter Path of the Directory"); 8             System.exit(0); 9         }else{10             File f=new File(args[0]);11             if(f.exists() && f.isDirectory())12             {13                 File[] list=f.listFiles();14                 System.out.format("%-70s%-10s%-10s%-15s\n","Name","Size","Type","Last Modified");15                 System.out.println("======================================================================================================================");16                 for(File file:list){17                     if(file.isDirectory())18                         dir="<DIR>";19                     else20                         dir="";21                     System.out.format("%-70s%-10s%-10s%-15s\n",file.getName(),file.length()/1024+" KB",dir,new Date(file.lastModified()));22                 }23             }24             else25                 System.out.println("Not an Existing Directory");26         }27     }28 29 }

 

File List