Java 移动文件到指定目录:
public void moveFile(){
String fromPath="D:\\test\\1.mp4";
String toPath="D:\\totest";
System.out.println("移动文件:从路径 " + fromPath + " 移动到路径 " + toPath);
File file = new File(fromPath);
if (file.isFile()){
File toFile=new File(toPath+"\\"+file.getName());
if (toFile.exists()){
System.out.println("文件已存在");
}
else{
file.renameTo(toFile);
System.out.println("移动文件成功");
}
}
}
}