• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

copying files from folder

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

Using java code(jdk 1.5),
I want to copy some files which are present in 1 folder to another folder.
The files are not of any specific type, it is .doc, .jar files etc...

e.g. Files present in D:\files want to copy them into D:\CD_Source.

I would appreaciate your help...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Java in General (intermediate).
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you haven't done so yet, you should have a look at
the code recipes in the Farmer's ^H^H^H Java Almanac:
http://javaalmanac.com/egs/java.io/CopyFile.html
http://javaalmanac.com/egs/java.nio/File2File.html
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use Runtime object and pass the command to copy to it
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

you can use Runtime object and pass the command to copy to it

This becomes more platform dependent. The better wy is to use java.io package
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but the links provided are to copy a file to another file.how will we get the list of all files in one folder.Then we have to iterate through that list and do the functionality provided in the links listed to copy the file I guess
 
Sri Ram
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Renu Radhika:
but the links provided are to copy a file to another file.how will we get the list of all files in one folder.Then we have to iterate through that list and do the functionality provided in the links listed to copy the file I guess


This is more of IO question than a General Java Post

Anyway, Yes u have to get the list of files in the directory, iterate one by one and copy each of them.

for listing check java.io.File class. The method is list() . This method will give u the list of file in a directory.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better yet, I recommend the listFiles() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic