Fri Oct 15 2021
Move File
Java Programming933 views
File Name: move-file.java
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!
Reference:
Author:Geekboots