移动文件

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();
        }

    }

}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。