Move File

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!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!