954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to overwrite a counter value on monitor screen

Hello,

I am writing a java program that reads a flat file and process each record. I am maintaining a counter that keeps track of the record/ line being processed.

I want to print this counter on the monitor screen. Using
System.out.printf("Processing Record: %d\r", counter);

is printing the the required string, but it is printing new output line for every counter value. Like this:

Processing Record: 1
Processing Record: 2
Processing Record: 3

and so on.

I want to overwrite the line continously and not write new lines. Like:
Processing Record: 1 (with the number being overwritten everytime a new record is processed)

Can someone show me how, please. I will be grateful if anyone can give some hints.

Reuben

Reuben98
Newbie Poster
2 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

Console output is line based and non-exclusive.
Never assume you will have the entire screen or even an entire line at your disposal.

So you're not supposed to go back to a previous screen location and write there because it likely no longer contains what you originally wrote there (having scrolled away).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Thanks for the reply. I think I understand now:)

In regards to console output, I guess there is no difference between \r (carriage return) and \n (new line) in the format syntax.

My other alternative is now to create a JFrame/ window and display the counter there. I hope that will work.

Thanks again for your kind response.

Reuben

Reuben98
Newbie Poster
2 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You