首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

怎么使用FileChannel

2012-10-07 
怎样使用FileChannel怎样使用FileChannel?FileChannel定义了两个用于文件传输的方法:1. transferTo(int po

怎样使用FileChannel

怎样使用FileChannel

?

FileChannel定义了两个用于文件传输的方法:

1. transferTo(int position, long count, WritableByteChannel dst)

??? 该方法是把文件从position位置开始向dst通道传送count个字节。

?

2. transferFrom(ReadableByteChannel src, long position, long count)

??? 该方法是将count个字节从通道src传送到文件中,position是为文件开始写入的位置。

?

从FileInputStream中获得的FileChannel对象只支持transferTo,而从FileOutputStream中获得的FileChannel对象只支持tansferFrom()方法。

?

FileChannel?sfc?=?new?FileInputStream(“D://temp//from.txt”).getChannel();

FileChannel?tfc?=?new?FileOutputStream(“D://temp//to.txt”).getChannel();

sfc.transferTo(0,?sfc.size(),?tfc);

sfc.close();

tfc.close();

?

?

?

?

热点排行