【发布时间】:2013-12-24 19:41:06
【问题描述】:
在我的 Web 应用程序中,客户端可以从服务器下载文件。 我的代码看起来有点像这样:
public void downloadFile(HttpServletResponse response, String fileName){
File fileToDownload = getFileWithName(fileName);
updateContentTypeAndLength(response);
OutputStream out = response.getOutputStream();
FileUtils.copyFile(fileToDownload, out);
}
问题是我需要知道客户端何时完成下载文件,有没有办法让我知道? 谢谢。
【问题讨论】:
-
这似乎是客户端的责任。您的要求如何?
-
好吧,他们下载它的速度不会比你发送它的速度快,所以在
copyFile方法调用返回一段时间后。 -
你想做什么?
-
我的意图是尽我所能确保客户端确实获得了文件(完全下载)。我很确定一旦这个 'FileUtils.copyFile(fileToDownload, out);'结束了——这并不意味着客户端已经完成了这个文件的下载。
标签: java http client-server download fileutils