现在的位置: 首页 > 综合 > 正文

JAVA文件拷贝(NIO实现)

2013年10月18日 ⁄ 综合 ⁄ 共 576字 ⁄ 字号 评论关闭
java 文件拷贝通过NIO实现
http://www.exampledepot.com/egs/java.nio/File2File.html
  1.     try {
  2.         // Create channel on the source
  3.         FileChannel srcChannel = new FileInputStream("srcFilename").getChannel();
  4.     
  5.         // Create channel on the destination
  6.         FileChannel dstChannel = new FileOutputStream("dstFilename").getChannel();
  7.     
  8.         // Copy file contents from source to destination
  9.         dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
  10.     
  11.         // Close the channels
  12.         srcChannel.close();
  13.         dstChannel.close();
  14.     } catch (IOException e) {
  15.     }
【上篇】
【下篇】

抱歉!评论已关闭.