gpt4 book ai didi

java - nio FileChannel.transferFrom 传输0?

转载 作者:行者123 更新时间:2023-11-30 05:14:27 25 4
gpt4 key购买 nike

我正在尝试使用 NIO 通过transferFrom 将多个较小的文件组合成一个文件。

对transferFrom的调用返回0。也不异常(exception)。未执行任何操作来打开同步行为。

    FileOutputStream fos = new FileOutputStream(path);
FileChannel fileBeingAssembled = fos.channel();
int progressiveOffset = 4096;
FileInputStream fis = new FileInputStream(tmpT5);
FileChannel channel = fis.getChannel();
channel.position(0);
int thisItemLength = (int)channel.size();
LOG.info("Writing " + tag + " at " + progressiveOffset + " length " + thisItemLength);
fileBeingAssembled.position(progressiveOffset);
long x = fileBeingAssembled.transferFrom(channel, progressiveOffset, thisItemLength);
LOG.info("transferred " + x);
progressiveOffset += thisItemLength;

示例日志:

4409 [main] INFO  com.basistech.seg.writing.ModelOutputTask  - available 1856216
4409 [main] INFO com.basistech.seg.writing.ModelOutputTask - Writing word at 15024620 length 1856216
4419 [main] INFO com.basistech.seg.writing.ModelOutputTask - transferred 0

最佳答案

两个最明显的答案是:

  1. tmpT5 指向零字节文件,或者
  2. 路径指向的文件长度小于 4096 字节。

来自transferFrom文档:

If the given position is greater than the file's current size then no bytes are transferred.

关于java - nio FileChannel.transferFrom 传输0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2124499/

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