tags:

views:

76

answers:

2

I just tested the backspace escape as follows:

System.out.println("Hello\b");

I expected to get the output: Hell
But it was: "Hello" with a square block

anyone knows how java handle this?

+5  A: 

Java doesn't 'handle' that character it at all. All it knows about is a byte stream onto which the OS says it can write bytes, and it will happily write bytes into it, including an ASCII backspace.

What happens when the stream receives that character has nothing whatsoever to do with Java, it is totally terminal-dependent. Some terminals will erase the previous character, some will display the backspace character it as some weird glyph, or even as a special "backspace character" glyph. Some may drop the character altogether if they can't interpret it, others (most terminal emulators, in fact) will behave differently depending on how they're configured. But all this has nothing to do with Java, they will behave that way whether they're writte to by Java or Perl print or C++ cout or whatever else.

Kilian Foth
+1  A: 

It should work perfectly fine in Windows command console. This bug is recognizeable as an Eclipse bug: bug 76936. Also see How to get backspace \b to work in Eclipse’s console?

BalusC
thanks, but it still did not work in windows console as well. did you try this out on your machine. maybe it is my system problem.
Guoqin