5

I have a List which contains File type Object.
Eg.List < File > copyFile = new ArrayList < File >();
Now I want Copy this copyFile to d:\\demo\\ location.
AnyOne can tell me how to this ?
I know how to copy file from path to path.

Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
vijayk
  • 2,633
  • 14
  • 38
  • 59

1 Answers1

0

Below code will help you to list all the folder names

 class Folder {
      boolean isFile;
      String folderName;
      List<Folder> subFolders = new ArrayList<Folder>();
    }

class ListF {
  public static void main(String args[]) {
     File fname = new File("D:\\Demo\\");
     Folder obj = new Folder();
     if (fname.isDirectory()) {
        File[] fileNames;
        fileNames = fname.listFiles();
        for (i = 0; i < fileNames.length; i++) {
           obj.subFolders.add(fileNames[i]);
        }
        System.out.println("The list is " + obj.subFolders);
     }
   }
}

To copy directory below code is usefull

File source = new File("D:\\folder-path\\folder1");
File desc = new File("D:\\folder-path\\new folder");
FileUtils.copyDirectory(source, desc);
NPKR
  • 5,368
  • 4
  • 31
  • 48
Sudz
  • 4,268
  • 2
  • 17
  • 26