Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:27:22+00:00 2026-06-17T14:27:22+00:00

I have written a Java program that loads data from a file and I

  • 0

I have written a Java program that loads data from a file and I am displaying the progress of the load on the command line, by printing a message to the screen after every n records, which looks like this:

$> processed 100 records.

$> processed 200 records.

$> processed 300 records.

$> processed 400 records.

$> processed 500 records.

…

However, I would like to just print ONE line, and only update the number, i.e., so that the output always just looks like this:

$> processed < n > records.

How to do this in Java and, is it even possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:27:23+00:00Added an answer on June 17, 2026 at 2:27 pm

    It depends on your console, but the simplest way is to use the backspace character to move the cursor backwards, in front of the recently printed characters:

    int[] step = {100,200,300,400,500};
    System.out.print("$> processed < ");
    for (int i : step) {
       System.out.print(i + " > records.\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
       Thread.sleep(500);
    }
    

    This works on the windows command line, but for example it does not work on the Eclipse console.

    You should add some additional logic to count the numbers of characters printed, and not hard-code all these “\b” characters, but calculate the right number depending on the recent output.

    As @Reza suggests, using “\r” is even easier:

    int[] step = {100,200,300,400,500};
    for (int i : step) {
       System.out.print("$> processed < " + i + " > records.\r");
       Thread.sleep(500);
    }
    

    It does still not work on the Eclipse console (but is more readable than the backspace approach), but avoids the handling of all the backspace characters. If printing a shorter line than before, it might be necessary to print some additional spaces to clear trailing characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java program that reads some text from a file, line by
I have written java code for generating json of my searched data from file.But
I have a program written in Java that reads an excel file and output
I have written a Java program that reads in a file containing commands to
I have written a java program that is actually works as a gui to
I have written a java program that tests the speed of a couple of
I have written a program in Java to read in a text file of
I have written a Java program on my computer that searches on the net
I have a working program written in Java with the Java Sound API that
I have written a nice program in Java that connects to a gmail account

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.