繁体   English   中英

Java transferFrom二进制文件的一部分?

[英]Java transferFrom Part of binary file?

尝试使用RandomAccessFile transferFrom函数从位置1300(以uint8个数)开始的文件file传输到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十六进制数(原始标头是???)之外?

您想使用transferTo我相信

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

因为transferFrom尝试从outfile的第n个位置开始,而transferTo将从infile的n个位置开始

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM