qhnokia

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
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();
        }

    }

}

 

posted on 2014-09-19 16:47  其乐无穷  阅读(165)  评论(0编辑  收藏  举报