Advertisement
romancha

FileFirst

Mar 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import java.io.File;
  2.  
  3. public class MyFilesList {
  4.     public static void main(String[] args) {
  5.         try {
  6.             File directory;
  7.             if (args.length < 1) {
  8.                 directory = new File(System.getProperty("user.dir"));
  9.             } else {
  10.                 directory = new File(args[0]);
  11.             }
  12.  
  13.             if(directory.list().length > 0) {
  14.                 System.out.println(directory.getAbsoluteFile() + ":");
  15.                 for (String unit : directory.list()) {
  16.                     System.out.println("\t-" + unit);
  17.                 }
  18.             }
  19.         } catch (NullPointerException e) {
  20.             System.out.println("Incorrect file path: " +  args[0]);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement