• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

copying files from folder

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to Java in General (intermediate).
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use Runtime object and pass the command to copy to it
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better yet, I recommend the listFiles() method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic