deyanmalinov

7. List Files

Apr 8th, 2020
535
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) throws IOException {
  8.         String path = "D:\\Coding\\Java\\Softuni\\Java Advanced - January 2019\\" +
  9.                 "04. Java-Advanced-Fiels-and-Directories-Lab\\04. " +
  10.                 "Java-Advanced-Files-and-Streams-Lab-Resources\\Files-and-Streams";
  11.         File file = new File(path);
  12.         if (file.exists()) {
  13.             if (file.isDirectory()) {
  14.                 File[] files = file.listFiles();
  15.                 for (File f : files) {
  16.                     if (!f.isDirectory()) {
  17.                         System.out.printf("%s: [%s]%n",
  18.                                 f.getName(), f.length());
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.     }
  24. }
RAW Paste Data