my dog learned polymorphism*
The moose likes Java in General and the fly likes copying files from folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "copying files from folder" Watch "copying files from folder" New topic
Author

copying files from folder

Deboleena Chakraborty
Greenhorn

Joined: May 10, 2004
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61456
    
  67

Moved to Java in General (intermediate).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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


There is no emoticon for what I am feeling!
Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
you can use Runtime object and pass the command to copy to it
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228

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


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
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

Joined: Oct 03, 2005
Posts: 118
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

Joined: Jan 30, 2000
Posts: 18671
Better yet, I recommend the listFiles() method.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: copying files from folder