首页 > 编程语言 > 详细

java处理文件的复制

时间:2018-10-04 03:09:01      阅读:93      评论:0      收藏:0      [点我收藏+]

import java.io.File;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class FileCopy
{
public static void copyFileUsingFileChannels(String sourcePath, String destPath) throws IOException {
File source=new File(sourcePath);
File dest=new File(destPath);
dest.setExecutable(true);//设置可执行权限(发布在tomcat时若权限不足,没法进行操作则设置权限)
dest.setReadable(true);//设置可读权限
dest.setWritable(true);//设置可写权限

FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
inputChannel = new FileInputStream(source).getChannel();
outputChannel = new FileOutputStream(dest).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
inputChannel.close();
outputChannel.close();
}
}
}

 

java处理文件的复制

原文:https://www.cnblogs.com/LetMeKnow/p/9740181.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!