计算 FileUtils.copyURLToFile 写入文件的字节数?
Count bytes written to file by FileUtils.copyURLToFile?
如何计算 Apache Commons FileUtils.copyURLToFile
写入的字节数?
由于从 url 复制文件需要时间,而且您的 class 路径上已经有 Apache Commons,您可能需要使用 ConcurrentUtils
class 来解决您的问题。
long lengthInBytes = ConcurrentUtils.constantFuture(downloadFile()).get();
其中 downloadFile()
方法提供了一个实现,其中 returns 文件长度(以字节为单位)
public Long downloadFile() throws IOException {
File target = new File(fileName);
FileUtils.copyURLToFile(new URL(url), target);
return target.length();
}
如何计算 Apache Commons FileUtils.copyURLToFile
写入的字节数?
由于从 url 复制文件需要时间,而且您的 class 路径上已经有 Apache Commons,您可能需要使用 ConcurrentUtils
class 来解决您的问题。
long lengthInBytes = ConcurrentUtils.constantFuture(downloadFile()).get();
其中 downloadFile()
方法提供了一个实现,其中 returns 文件长度(以字节为单位)
public Long downloadFile() throws IOException {
File target = new File(fileName);
FileUtils.copyURLToFile(new URL(url), target);
return target.length();
}