Java 可以用来确定下载的持续时间吗?
只是问一下,你会如何做这件事。
我知道有一些方法可以获取总体百分比来通知用户下载进度,但我不知道如何在一段时间内执行类似的操作。
例如“下载完成所需时间:5 分钟”。
我所知道的只是百分比,写出写入的字节,然后将其除以长度,然后将其转换为百分比(如果我没记错的话,已经几个月没有执行上述操作了,所以我很生疏并且很健忘)
谢谢,出于好奇。
Just asking, and how would you go about doing this.
I know there is ways to get an overall percentage to inform users of the download's progress, but I haven't a clue on how I can do the similar for time.
E.g. "Time until download finishes: 5 minutes".
All I know is percentages, writing the bytes written then dividing it by the length and turning it into a percentage (if I recall correctly, haven't done the above for a few months, so I'm rusty and very forgetful)
Thanks, out of curiosity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于完全线性的模型,您只需将剩余下载的字节数除以迄今为止的平均下载速度:
如果您在所有地方都坚持以毫秒为单位,
timeLeft
将包含直到下载完成之前的估计毫秒数。完整文件已下载。要以小时和/或分钟和/或秒的形式正确输出,我建议您查看
For a completely linear model, you simply divide the number of bytes left to download by the so-far-average download speed:
If you stick to milliseconds everywhere,
timeLeft
will contain the estimated number of milliseconds until the full file is downloaded.To output that properly in terms of hours and/or minutes and/or seconds, I suggest you have a look at
是的,你可以。
不,没有任何“内置”的东西。
您的问题实际上(至少)有两个部分:
1)如何确定时间?
2)如何显示?
建议:
谷歌搜索“Java status bar”,然后查看一些可能满足您需求的代码。
建议:
看看 MS Vista 的“剩余时间”算法。无论 Vista 在做什么 - 不要那样做;)
Yes, you can.
No, there's nothing "built-in".
And there are actually (at least) two parts to your question:
1) How do I determine the time?
2) How do I display it?
Suggestion:
Google for "Java status bar", and look at some code that might do what you're looking for.
Suggestion:
Look at MS Vista's "time remaining" algorithm. Whatever Vista is doing - don't do that ;)