File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes System.out updating line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "System.out updating line" Watch "System.out updating line" New topic

System.out updating line

Martin Gilday

Joined: Jul 27, 2005
Posts: 4
This is probably really simple but I have never come across it before.
I am writing a transfer app and want to log progress back to the terminal. What I want to have is basically "Transfer: 50 of 600231". But I dont want to have a new line printed each time, just update the previous one. I know this is possible as Maven does this, when deploying and downloading. I had a look through the source but it is too vast to find where it is.

Is it possible to do this with some sort of Printer or are there any existing libs for doing this?

Joe Ess

Joined: Oct 29, 2001
Posts: 8836

The backspace character is 0x08. Print out the same number of backspaces as characters you've printed out. You could also probably use the carrage return character (0x0d), but I've never tried it.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Martin Gilday

Joined: Jul 27, 2005
Posts: 4
Thank you for your reply.
I have tried this System.out.print((char)0x08);
But I simply get a rectangle printed instead.
Martin Gilday

Joined: Jul 27, 2005
Posts: 4
Apologies. Seems that Eclipse cannot print backspace. Works perfectly from a terminal.

I agree. Here's the link:
subject: System.out updating line
Similar Threads
adding new lines to TextArea form value
conversion of html to java
accessing buffer to transfer data
So where is the Jobless Recovery?