Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Copying Directories  RSS feed

 
Asuthosh Borikar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to write some code to copy all the contents(including sub directories and files) of one directory to another directory.
I've tried using File.renameTo(), but, this method 'moves' the contents rather than copying them. Can some one please point me to a good algorithm of iterating thru the contents of a directory, and copying them to another? Thanks a lot.
-Asuthosh.
 
Graeme Brown
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there are a limited number of O/S that you need to run this on, you would probably be better making a call to the operating system commands using Runtime.exec()
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!