赞
踩
import java.io.File; import java.io.IOException; import java.nio.file.*; public class TestMoveFile { public static void main(String[] args)throws Exception { String temp="G:\\test\\1111.txt"; String targetTemp=temp.substring(0,temp.lastIndexOf(File.separator)+1)+"backuptar"; //System.out.println(targetTemp+"111111111111111111===================="); //+temp.substring(temp.lastIndexOf("/"),temp.length()); //temp.substring(0,temp.lastIndexOf("/")+1)+"backuptar"+temp.substring(temp.lastIndexOf("/"),temp.length()) System.out.println(targetTemp); File targetPart=new File(targetTemp); if(!targetPart.exists()){ targetPart.mkdirs(); } targetTemp=targetTemp+File.separator+temp.substring(temp.lastIndexOf(File.separator)+1,temp.length()); System.out.println(targetTemp+"222222222222=========================="); Path sourcePath = Paths.get(temp); Path targetPath = Paths.get(targetTemp); try { Files.move(sourcePath, targetPath, StandardCopyOption.ATOMIC_MOVE); System.out.println("成功了"); } catch (IOException e) { System.out.println("失败了"); e.printStackTrace(); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。