• Post Reply Bookmark Topic Watch Topic
  • New Topic

Recursive copying and pasting of files  RSS feed

 
Prabha Dhandapani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I have a folder that has .xml files in it!I need to write a program for copying all the .xml files to a different directory or folder.
my dir structure is as follows:
a/aa/atoz/xml/aa/aa.xml1
a/aa/atoz/xml/bb/bb.xml2...
I have written a program that reads the name of the file when i specify the path as a/aa/atoz/xml/aa/.
I need to specify the path as the root ie a/aa/atoz/xml/.If the search for the file is a folder then i need to do a recursive process.
It would be great if someone could help me solve this problem with an example.Looking for help!
Many Thanks in Advance,
Prabha
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.io.File is all you need. The list() method returns the contents of a directory and you can use isDirectory() or isFile() to process the contents.
 
Prabha Dhandapani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe!
I have wrriten the code to find if it is a file or a dir.
The next thing is ,how can I copy the file and put it another folder?Can u tell me the classes that I need to use?
Help me!
Thanks,
Prabha
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should familiarize yourself with the Java Tutorial. It has lots of useful information, such as a chapter on I/O: Reading and Writing that even has an example of copying a file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!