import java.io.File;
public class MoveFile {
public static void main(String[] args) {
String src="c:/Autoexec.bat";
String dest="d:/";
MoveFile mf=new MoveFile();
mf.move(src, dest);
}
public static boolean move(String srcFile,String destPath){
File file=new File (srcFile);
File dir=new File(destPath);
boolean success=file.renameTo(new File(dir,file.getName()));
if(success){
System.out.println("文件移动成功!");
}
else{
System.out.println("文件移动失败!");
}
return success;
}
}
运行结果:文件移动成功!