How to move file from one directory to another in Java

1 Answer

0 votes
package javaapplication1;
 
import java.io.*;
 
public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            File file = new File("d:\\data.bin");

            if (! file.exists()) 
                throw new java.io.IOException("file d:\\data.bin - not exists");

            if (file.renameTo(new File("d:\\test\\" + file.getName())))
    		    System.out.println("move success");
    	    else
    		    System.out.println("move failed");
        }
        catch (Exception e) 
        {
            System.out.println("Error rename file: " + e.getMessage());   
        }
    }
}
 
/*
 
run:
 
move success
 
*/

 



answered Aug 29, 2015 by avibootz

Related questions

1 answer 240 views
1 answer 220 views
2 answers 227 views
3 answers 282 views
3 answers 268 views
1 answer 262 views
3 answers 323 views
...