0

Currently, my program prints to System.out:

Processing line 1 of 3...
Processing line 2 of 3...
Processing line 3 of 3...

Is there any way to have it replace the line numbers, instead of printing a new line?

4
  • 1
    stackoverflow.com/questions/439799/… Commented Feb 7, 2015 at 21:55
  • 1
    Without using a library, you could just print a '\r' (Return to the start of the line) and thus overwrite what you just printed. Commented Feb 7, 2015 at 21:56
  • System.out.print(), didn't write at the same line?... Commented Feb 7, 2015 at 21:56
  • 1
    possible duplicate of How can I print to the same line? Commented Feb 7, 2015 at 22:08

1 Answer 1

1

Well there are some hacks you can try, but none of them are guaranteed to work everywhere. Escape characters such as \b (backspace) can erase the last character and \r (replace) can erase the last output.

It may or may not work (depending on IDE), but you could try:

System.out.print("Hello");
Thread.sleep(1000);
System.out.print("\rWorld");

However, generally a Swing box should be used (dynamically updating GUI) to measure progress. See Progress Bars.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.