Java transferFrom部分二进制文件?

时间:2013-11-25 06:25:31

标签: java randomaccessfile

尝试使用RandomAccessFile transferFrom函数从位置1300(uint8件)开始从文件filein转移到fileto。

fromfile = java.io.RandomAccessFile(ifile, 'rw');
fromchannel = fromfile.getChannel();
tofile = java.io.RandomAccessFile(ofile, 'rw');
tochannel = tofile.getChannel();
tochannel.transferFrom(fromchannel,n,fromfile.length()-n)

tochannel.close();
fromchannel.close();
fromfile.close();
tofile.close();

我的输出文件只是空的。

任何人都知道我做错了什么?

编辑1:

我已经改变了

tochannel.transferFrom(fromchannel,n,fromfile.length()-n)

fromchannel.transferTo(n,fromfile.length()-n,tochannel)

但是现在输出正在打印到所有文件,除了它放了很多00十六进制数,其中原始标题是???

1 个答案:

答案 0 :(得分:1)

你想使用transferTo我相信

fromchannel.transferTo(n,fromfile.length()-n,tochannel)

transferFrom尝试从outfile中的位置n开始,而transferTo将从infile中的位置n开始

相关问题