0

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

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Reuben98
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).

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.