- /**
- * 移动文件到指定的目录
- *
- * 将文件从test文件夹移动到test2文件夹
- *
- */
- 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();
- }
- }
- }
转载于:https://www.cnblogs.com/Darkqueen/p/8966048.html