首页 > 代码库 > 移动文件

移动文件

package test;import java.io.File;public class MoveFile {    public static void main(String[] args) {        try {            // File file = new File("C:/log/101/1001/log.txt");            //            // File dir = new File("C:/log/1001/log.txt");            // boolean success = file.renameTo(new File(dir, file.getName()));            File srcFolder = new File("C:/log/101/1001");                        System.out.println(srcFolder.getName());                                    File destFolder = new File("C:/log");                        System.out.println(destFolder.getAbsoluteFile());                                    File newFile = new File(destFolder.getAbsoluteFile() + "/"                    + srcFolder.getName());                        boolean success = srcFolder.renameTo(newFile);            if(!success){                System.out.println("error: " + srcFolder);            }            System.out.println(success);        } catch (Exception e) {            e.printStackTrace();        }    }}

 

移动文件