Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move all files from folder to other folder with java [duplicate]

Tags:

java

Possible Duplicate:
Copying files from one directory to another in Java

How can I move all files from one folder to other folder with java? I'm using this code:

import java.io.File;

    public class Vlad {

        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            // File (or directory) to be moved
            File file = new File("C:\\Users\\i074924\\Desktop\\Test\\vlad.txt");

            // Destination directory
            File dir = new File("C:\\Users\\i074924\\Desktop\\Test2");

            // Move file to new directory
            boolean success = file.renameTo(new File(dir, file.getName()));
            if (!success) {
                System.out.print("not good");
            }
        }
    }

but it is working only for one specific file.

thanks!!!

like image 503
vlio20 Avatar asked Sep 24 '12 11:09

vlio20


1 Answers

By using org.apache.commons.io.FileUtils class

moveDirectory(File srcDir, File destDir) we can move whole directory

like image 91
NPKR Avatar answered Oct 15 '22 19:10

NPKR