Code to move,rename and delete a file is below.
try{
//To move a file from one folder to another we do the following.
Path fileToMove = FileSystems.getDefault().getPath("Examples","filecopy.txt");
Path destination = FileSystems.getDefault().getPath("Examples","Dir1","filecopy.txt");
Files.move(fileToMove,destination);
/*Renaming a file is similar to move. We do the same as above. Only difference is source and destination folder
are the same. that is move the file to the same folder. only name it differently*/
Path fileToMove = FileSystems.getDefault().getPath("Examples","file1.txt");
Path destination = FileSystems.getDefault().getPath("Examples","file1.txt");
Files.move(fileToMove,destination);
// Lets delete a file now
Path fileToDelete = FileSystems.getDefault().getPath("Examples","Dir1","filecopy.txt");
Files.delete(fileToDelete);
//Please note the above line of code will throw an error if file to be deleted does not exist.
//To overcome this exception we use the following
Files.deleteIfExists(fileToDelete);
}
catch(IOException e){
System.out.println(e.getMessage());
}