Java退格键 [英] Java backspace escape

查看:297
本文介绍了Java退格键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚测试了退格空格,如下所示:

I just tested the backspace escape as follows:

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

我预计得到输出:Hell

但它是:你好有一个方块

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

任何人都知道java如何处理这个?

anyone knows how java handle this?

推荐答案

p> Java根本不'处理'这个字符。所有它知道的是一个字节流,操作系统表示它可以写入字节,并且它会愉快地写入字节,包括一个ASCII退格。

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.

当流接收到该角色与Java无关的时候,发生,它完全与终端无关。有些终端会擦除上一个字符,有些终端会将退格字符显示为一些奇怪的字形,甚至会显示为特殊的退格字符字形。有些人如果不能解释它们,可能会丢掉这个角色,其他人(实际上大多数终端仿真器)的行为会因应如何配置而有所不同。但是所有这一切与Java无关,他们将以这种方式表现出来,无论他们是通过Java或Perl写的,或C ++ cout 或其他任何东西。

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.

这篇关于Java退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆