Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

escaping - Java backspace escape

I just tested the backspace escape as follows:

System.out.println("Hello");

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

anyone knows how java handle this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Java doesn't 'handle' that character 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 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 written to by Java or Perl print or C++ cout or whatever else.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...