码迷,mamicode.com
首页 > 编程语言 > 详细

java处理文件的复制

时间:2018-10-04 08:53:14      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:ring   tran   setw   source   nal   exe   read   null   throws   

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处理文件的复制

标签:ring   tran   setw   source   nal   exe   read   null   throws   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!