gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:48:08 24 4
gpt4 key购买 nike

我尝试使用 RandomAccessFile TransferFrom 函数从位置 1300(以 uint8 block 形式)开始的文件 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 十六进制???

最佳答案

我相信你想使用transferTo

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

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

关于Java TransferFrom 二进制文件的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20186047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com