苏强的专栏

做最优秀的自己

原创 使用FileChannel复制文件收藏

新一篇: 使用apache.commons.fileupload 进行文件上传 | 旧一篇: 根据URL从服务器端复制文件到本地java代码

文件通道定义了两个方法,可以进行直接的文件传输:
int transferTo(int position,long count,WritableByteChannel dst);
这个函数是把文件从position位置开始向dst通道传送count个字节。
int transferFrom(ReadableByteChannel src,long position,long count);
将count个字节从通道src传送到文件中,position是为文件开始写入的位置。
从FileInputStream中获得的通道只支持transferTo,而从FileOutputStream中获得的通道只支持tansferFrom()方法

  1. FileChannel sfc = new FileInputStream(“D:\\suqiang\\from.txt”).getChannel();
  2. FileChannel tfc = new FileOutputStream(“D:\\suqiang\\to.txt”).getChannel();
  3. sfc.transferTo(0, sfc.size(), tfc);
  4. sfc.close();
  5. tfc.close();

发表于 @ 2008年09月24日 17:46:00|评论(loading...)|收藏

新一篇: 使用apache.commons.fileupload 进行文件上传 | 旧一篇: 根据URL从服务器端复制文件到本地java代码

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 苏强