JAVA IO 没有提供直接的移动方法,但是可移动renameTo来实现移动文件。
import java.io.File;public class MoveFileExample { public static void main(String[] args) { try{ File afile =new File("C:\\work\\hello\\helloworld.txt"); if(afile.renameTo(new File("C:\\work\\hello\\hello\\" + afile.getName()))){ System.out.println("File is moved successful!"); }else{ System.out.println("File is failed to move!"); } }catch(Exception e){ e.printStackTrace(); } }}