java nio复制文件
作者:
不知不怪 | 来源:发表于
2019-10-14 17:16 被阅读0次public void copyFile(String src, String des) {
try {
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(des);
FileChannel inchannel = fis.getChannel();
FileChannel outchannel = fos.getChannel();
ByteBuffer buf = ByteBuffer.allocate(1024 * 1024);
while (inchannel.read(buf) != -1) {
buf.flip();
outchannel.write(buf);
buf.clear();
}
outchannel.close();
inchannel.close();
fis.close();
fos.close();
} catch (FileNotFoundException e) {
log.info("复制文件时发FileNotFoundException导常!", e);
} catch (IOException e) {
log.info("复制文件时发IOException导常!", e);
}
}
本文标题:java nio复制文件
本文链接:https://www.haomeiwen.com/subject/flarmctx.html
网友评论