使用Path.resolve()方法通过直接从movefrom路径中提取文件名来移动文件
import java.io.IOException; /* 来 自* 时代Java - nowjava.com */ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; public class Main { public static void main(String[] args) throws Exception { Path movefrom = FileSystems.getDefault().getPath( "C:/folder1/test.jpg"); Path moveto_dir = FileSystems.getDefault().getPath("C:/folder1/photos"); try { Files.move(movefrom, moveto_dir.resolve(movefrom.getFileName()),