在Java中打印'\\\' [英] printing '\u0000' in Java

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

问题描述

当我执行

char c= '\u0000'; 
System.out.println(c);

在Eclipse中,它打印一个小方块,这意味着一个空字符。

但是当我在CLI中运行它时,它打印'a'。

然后我在其他计算机上运行它,有些打印'a',有些打印一个空格。

in Eclipse,it prints a little square which means a null character.
But it prints 'a' when I run it in CLI.
Then I run it on other computers, some print 'a', some print a space.

为什么会发生这种情况?

Why would this happen?

我的操作系统是Windows 7专业32位。其他系统是windows xp。

我的java版本是jdk_1.6.0update12。

My OS is Windows 7 professional-32bit.The other systems are windows xp.
My java version is jdk_1.6.0update12.

推荐答案

它不为我打印:

public class Mkt {
 public static void main(String[] args) {
    char c= '\u0000'; 
    System.out.println("-" + c + "-");
  }
}

$ javac Mkt.java && java Mkt
--

Ubuntu 11.10这里:

Ubuntu 11.10 here:

$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

检查/尝试的内容:


  • 更改终端窗口的字体

  • 与其他Java版本在您的机器上?

  • 您的机器与您尝试的其他机器之间有不同的东西吗?

  • Cygwin

  • 尝试一些不同的控制台模拟器,例如控制台

  • 重定向到文件( http://docs.oracle.com/javase/6/docs/api/javax/swing/JTextArea.html =nofollow> JTextArea ,看看它是否显示相同

  • \\\ 显示什么?

  • Change the font of your terminal window
  • Did you try with other Java versions on your machine?
  • Is there something different between your machine and others you tried?
  • Try it from within Cygwin
  • Try some different console emulator, e.g. Console
  • Redirect to file (java Mkt > some_file.txt) and see what's in it, preferably with some hex editor
  • Make a small Swing application and display that in JTextArea to see if it displays the same
  • What does \u0001 display?

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

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