I have tried many times to clear the console and have written this Runtime.getruntime.exec("cls"); but did not get any result, means the console is not being cleared in Windows .
System.out.print("\\b")
might do the trick. One \\b
for each character printed.
System.out.print("Foo");
System.out.print("\b\b\b");
System.out.print("Bar");
This prints "Bar"
String foo = "Foo";
System.out.print(foo);
for (int i = 0; i < foo.length(); i++) {
System.out.print("\b");
}
System.out.print("Bar");
Same result using a loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.