• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Copying multiple files from one folder to another java  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to copy multiple files from one folder to another,

Path path1 = Paths.get("C:\\Users\\320053202\\testdir1");
Path path2 = Paths.get("C:\\Users\\320053202\\testdir2");
Path copy = Files.copy(path1, path2);

I thought File copy will be same as the files inside a folder to be copied
I have used java.nio package

Please help me out
 
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the Jaa™ Tutorials. That says,

. . . The copy fails if the target file exists, unless the REPLACE_EXISTING option is specified.

Directories can be copied. However, files inside the directory are not copied, so the new directory is empty even when the original directory contains files. . . .

You are going to have to find the individual files an copy them. Alternatively, unless the files are small, find out how to open a channel between the two directories. I have forgotten how to myself.
 
Usha Viswanathan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Look in the Jaa™ Tutorials. That says,

. . . The copy fails if the target file exists, unless the REPLACE_EXISTING option is specified.

Directories can be copied. However, files inside the directory are not copied, so the new directory is empty even when the original directory contains files. . . .

You are going to have to find the individual files an copy them. Alternatively, unless the files are small, find out how to open a channel between the two directories. I have forgotten how to myself.



Target directory is empty and it does not have the same file name as the source directory

I tried iterating the files present in source directory and copied the same using Files.copy method but getting FileAlreadyExistingException

Could you please tell me how to proceed
 
Campbell Ritchie
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ddn't the link I gave you tell you what to do?
 
Bartender
Posts: 5775
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post a more complete piece of source code, like including the code where you are doing the iterating?
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!