How to copy file and replaces the existing file in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        FileSystem fs = FileSystems.getDefault();
        
        Path source = fs.getPath("d:\\image.jpg");
        Path dest = fs.getPath("d:\\image-back.jpg");

        try {
            
	    Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
            
	} catch (IOException ex) {
	    System.out.println(ex);
	}
    }
}


/*
                   
run:

          
 */

 



answered Dec 17, 2016 by avibootz

Related questions

1 answer 207 views
1 answer 153 views
1 answer 186 views
3 answers 282 views
...