I've written a program in Java to use chunking to download large files over http. Everything is working fine but I'd like to add a progress bar which I can't do unless I get the total length of the file. Is there any way to do this?
If the server provides a Content-Length
header field, then that's easy. If it doesn't, then you're out of luck.
Reasonable server implementations provide Content-Length
when the content is static and has a known size. If the content is dynamically generated, then it's impossible to know the length a priori, at least without making two passes through the data.
来源:https://stackoverflow.com/questions/6285024/getting-total-file-length-when-using-chunked-http-transfers