Advertisement
nRikee

Comando ls | Blog nRikee

Dec 9th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. /** nrikee.wordpress.com */
  4.  
  5. public class ls
  6. {
  7.     public static void main(String args[]){
  8.     String nom;
  9.     if(args.length==0) nom = ".";
  10.     else nom = args[0];
  11.  
  12.         File f = new File(nom);
  13.  
  14.         if( f.exists() ) {
  15.             if ( !f.isDirectory() )  System.out.println("Nom fitxer: " +f.getName()+ "\nTamany: " + f.length() );
  16.             else {
  17.                 File[] fitxers = f.listFiles();
  18.                 System.out.println("Nom\t\tTamany");
  19.                 for (int a=0; a<fitxers.length; a++)
  20.                     System.out.println( fitxers[a].getName()+ "\t" + fitxers[a].length()  );
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement