如何计算Appache Commons FileUtils.copyURLToFile
写入的字节数?
答案 0 :(得分:1)
由于从url复制文件需要时间,并且您已经在类路径上安装了Apache Commons,因此您可能希望使用ConcurrentUtils
类来解决您的问题。
long lengthInBytes = ConcurrentUtils.constantFuture(downloadFile()).get();
其中downloadFile()
方法提供了一个实现,它以字节为单位返回文件长度
public Long downloadFile() throws IOException {
File target = new File(fileName);
FileUtils.copyURLToFile(new URL(url), target);
return target.length();
}