Java Programming

Move File

Java programming example for move file from a directory to another

10/15/2021
0 views
move-file.javaJava
import java.io.*;
import java.nio.file.*;
import static java.nio.file.StandardCopyOption.*;

class movefile {
	public static void main(String args[ ]) throws IOException {
		Path success = null;
		File src = new File("/home/user/Documents/abc.txt");

		/* Destination directory */
		File des = new File("/home/user/abc.txt");
		if(Files.isReadable(src.toPath())) {

			/* Move file to new directory */
			success = Files.move(src.toPath(), des.toPath(), REPLACE_EXISTING);
			System.out.println("File successfully move to: "+success);
		}
		else
			System.out.println("File not found!");
	}
}




/* Output */
File has been deleted successfully!

/* ---------------------- */

File not found or not able to deleted!
Java tutorialMove FileMoving file

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com