读取文件缓冲区将档案(zip、jar等)视为目录,并抛出IOException



我需要将大文件分割成2MB的切片,以便跨桥传输。下面的代码块适用于除归档文件(zip、jar等(之外的所有文件类型,它为归档文件抛出IOException,其消息为";是一个目录;。

try (FileChannel fileChannel = FileChannel.open(fullpath); WriteStream writeStream = channel.connect().orElseThrow()) {
byte[] bytes = origFileName.getBytes();
ByteBuffer buffer = ByteBuffer.allocate(maxsize - 10);
buffer.putChar('M');
buffer.put(bytes);
buffer.flip();
writeStream.write(buffer);
while (fileChannel.position() < fileChannel.size()) {
buffer = ByteBuffer.allocate(maxsize - 10);
buffer.putChar('D');
fileChannel.read(buffer);
buffer.flip();
writeStream.write(buffer);
}
} catch (IOException e) {
LOG.error("IO exception " + e.getMessage() + ", " + origFileName, e);
}

日志中的错误为:

IO exception Is a dir, file.zip

该错误是由"fileChannel.read(buffer("语句引发的。如果您能为我确定如何修复此问题提供任何帮助,我们将不胜感激。

事实证明,上游进程正在将zip文件转换为目录。请不要再在这个问题上浪费时间了。很抱歉,我在发帖前没有更好地研究一下情况。

最新更新