Java:在命令行中更新文本而不换行
我想向命令行 Java 程序添加进度指示器。
例如,如果我使用 wget,它会显示:
71% [===========================> ] 358,756,352 51.2M/s eta 3s
是否可以有一个无需在底部添加新行即可更新的进度指示器?
谢谢。
I'd like to add a progress indicator to a command-line Java program.
For example, if I'm using wget, it shows:
71% [===========================> ] 358,756,352 51.2M/s eta 3s
Is it possible to have a progress indicator that updates without adding a new line to the bottom?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用以下代码:
结果:
I use following code:
The result:
首先,当你编写时,不要使用
writeln()
。使用write()
。其次,您可以使用"\r"
来回车,而不使用\n
(换行符)。回车应该让你回到行的开头。First when you write, don't use
writeln()
. Usewrite()
. Second, you can use a"\r"
to Carriage Return without using\n
which is a New line. The carriage return should put you back at the beginning of the line.