Java:在命令行中更新文本而无需换行

2022-01-11 00:00:00 console console-application java

我想在命令行 Java 程序中添加进度指示器.

I'd like to add a progress indicator to a command-line Java program.

例如,如果我使用 wget,它会显示:

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?

谢谢.

推荐答案

首先写的时候不要使用writeln().使用写().其次,您可以使用"来回车而不使用 ,这是一个换行符.回车应该让你回到行首.

First when you write, don't use writeln(). Use write(). Second, you can use a "" to Carriage Return without using which is a New line. The carriage return should put you back at the beginning of the line.

相关文章