`
v64500
  • 浏览: 22221 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论

使用java复制移动文件

    博客分类:
  • java
阅读更多
移动文件

    public static boolean move(String srcFile, String destPath){
        // File (or directory) to be moved
        File file = new File(srcFile);
       
        // Destination directory
        File dir = new File(destPath);
       
        // Move file to new directory
        boolean success = file.renameTo(new File(dir, file.getName()));
       
        return success;
    }



复制文件
private void copyFile(File in, File out) throws Exception{
        FileChannel sourceChannel= new FileInputStream(in).getChannel();
        FileChannel destinationChannel= new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        // or
        // destinationChannel.transferFrom(sourceChannel, 0,
        // sourceChannel.size());
        sourceChannel.close();
        destinationChannel.close();
        sourceChannel= null;
        destinationChannel= null;
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics