Package | Description |
---|---|
org.dromara.hutool.core.io.copy |
IO流拷贝相关封装相关封装
|
Class and Description |
---|
FileChannelCopier
FileChannel 数据拷贝封装
FileChannel#transferTo 或 FileChannel#transferFrom 的实现是平台相关的,需要确保低版本平台的兼容性
例如 android 7以下平台在使用 ZipInputStream 解压文件的过程中,
通过 FileChannel#transferFrom 传输到文件时,其返回值可能小于 totalBytes,不处理将导致文件内容缺失
// 错误写法,dstChannel.transferFrom 返回值小于 zipEntry.getSize(),导致解压后文件内容缺失
try (InputStream srcStream = zipFile.getInputStream(zipEntry);
ReadableByteChannel srcChannel = Channels.newChannel(srcStream);
FileOutputStream fos = new FileOutputStream(saveFile);
FileChannel dstChannel = fos.getChannel()) {
dstChannel.transferFrom(srcChannel, 0, zipEntry.getSize());
}
|
IoCopier
IO拷贝抽象,可自定义包括缓存、进度条等信息
此对象非线程安全 |
Copyright © 2025. All rights reserved.