开发者

In Scala or Java, how to print a line to console replacing its previous content instead of appending?

A Scala application does some data processing. It would be nice to show processing progress in percents overwriting previous value on change rather than appendin开发者_运维技巧g a new value to what's already displayed. How to acheive this effect? I use Scala 2.8 on Linux.


Your easiest options are to use the carriage return without linefeed "\r" or the backspace character "\u0008". If you backspace, you need to keep track of how many characters you've emitted so you can back up enough (and blank out any excess). If you carriage return, you need to rewrite the entire line (and write spaces to blank out any excess).


If you were programming in C/C++, the answer would unequivocably be "ncurses".

There is a curses implemention in Java you might be interested in:

Java Curses

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜