public class MoveFile {
public static void main(String[] args) {
try {
File afile = new File("C:\\test\\test.txt");
if (afile.renameTo(new File("C:\\test2\\" + afile.getName()))) {
System.out.println("File is moved successful!");
} else {
System.out.println("File is failed to move!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}