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

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).

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.