public void fileChannelCopy(File srcfile, File destfile) {
FileInputStream fis= null;
FileOutputStream fos= null;
FileChannel fcin = null;
FileChannel fcout = null;
try {
fis = new FileInputStream(srcfile);
fos = new FileOutputStream(destfile);
fcin = fis.getChannel();//得到对应的文件通道
fcout = fos.getChannel();//得到对应的文件通道
fcin.transferTo(0, fcin.size(), fcout);//连接两个通道,并且从ifcn通道读取,然后写入fcout通道
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
fcin.close();
fos.close();
fcout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
网友评论