Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public static void main(String[] args) throws InterruptedException, IOException {
  2. ArrayList<String> selectFiles = new ArrayList<>();
  3. File folder = new File("путь");
  4. File[] listOfFiles = folder.listFiles();
  5.  
  6. for (File f : listOfFiles) {
  7. selectFiles.add(f + "");
  8. }
  9.  
  10. File source = new File(" " + selectFiles);// ПОЛУЧАЮ СПИСОК ФАЙЛОВ ПРИСВАИВАЮ ПЕРЕМЕННУЮ С ФАЙЛАМИ
  11. File dest = new File("путь");// ПРОПИСЫВАЮ ПУТЬ КУДА КОПИРОВАТЬ
  12. copy(source, dest);
  13. }
  14.  
  15. public static void copy(File source, File dest) throws IOException {
  16. Files.copy(source.toPath(), dest.toPath());
  17. }
  18.  
  19. private static void copyDir(String sourceDirName, String targetSourceDir) throws IOException {
  20. File folder = new File(sourceDirName);
  21.  
  22. File[] listOfFiles = folder.listFiles();
  23.  
  24. Path destDir = Paths.get(targetSourceDir);
  25. if (listOfFiles != null)
  26. for (File file : listOfFiles)
  27. Files.copy(file.toPath(), destDir.resolve(file.getName()), StandardCopyOption.REPLACE_EXISTING);
  28.  
  29. }
  30.  
  31. for (File f : listOfFiles) {
  32. Files.copy(f.toPath(), new File("путь" + File.separator + f.getName()).toPath());
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement