首页 > 其他 > 详细

文件拷贝

时间:2015-06-24 19:25:48      阅读:180      评论:0      收藏:0      [点我收藏+]
  Path path_from= Paths.get("d:\\深入剖析.pdf");

  Path path_to=Paths.get("d:\\深入剖析123.pdf");

  long startTime,endtime;

  try {

   FileChannel fileChannel_from=FileChannel.open(path_from, EnumSet.of(StandardOpenOption.READ));

   FileChannel fileChannel_to=FileChannel.open(path_to, EnumSet.of(StandardOpenOption.CREATE_NEW,StandardOpenOption.WRITE));

   startTime=System.currentTimeMillis();

   ByteBuffer byteBuffer=ByteBuffer.allocate(2048);

   int b;

   while ((b=fileChannel_from.read(byteBuffer))>0) {

    byteBuffer.flip();

    fileChannel_to.write(byteBuffer);

    byteBuffer.clear();

    

   }

   endtime=System.currentTimeMillis()-startTime;

   System.out.println(endtime);

  } catch (Exception e) {

   e.printStackTrace();

  }

文件拷贝

原文:http://my.oschina.net/u/1457061/blog/470343

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