Advertisement
Guest User

List all files in a directory and get absolute path

a guest
Nov 29th, 2013
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.File;
  2. import java.util.Arrays;
  3. import java.util.List;
  4.  
  5. public class Test {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         String targetFolder = "/home/you/";
  10.         File folder = new File("C:\\");
  11.  
  12.         System.out.println("folder=" + folder);
  13.         if (folder.listFiles() != null) {
  14.             List<File> listOfFiles = Arrays.asList(folder.listFiles());
  15.             for (File file : listOfFiles) {
  16.                 System.out.println("File name: " + file.getName());
  17.                 System.out.println("Full path: " + file.getAbsolutePath());
  18.                 System.out.println("Target path: " + targetFolder + file.getName());
  19.                 System.out.println();
  20.             }
  21.         }
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement