Is it possible to call println in Java?

Say I'm creating a command line interface. I want to print a line and then change it. For example, when you run a program, it prints

Hello, World!

A few seconds later, the message changed to:

Hello, Computer User!

Is it possible? Cross-OS is preferred.

+5
source share
2 answers

You can repeat the escape sequence \b, which is the backspace, and then write a new message instead of the old one.

Remember that this may not be completely cross-platform, as it depends on the console itself and how it interprets \b, but it should work mostly.

+5
source

to try

    String s1 = "Hello, word!";
    System.out.print(s1);
    Thread.sleep(1000);
    for(int i = 0; i < s1.length(); i++) {
        System.out.print('\b');
    }
    System.out.print("Hello, computer user");

, Eclipse,

+3

All Articles