终端Mac的麻烦(ENCODING) - 不显示来自Java的字符> 127 [英] Trouble with Terminal Mac (ENCODING) - Not displaying character from Java >127

查看:119
本文介绍了终端Mac的麻烦(ENCODING) - 不显示来自Java的字符> 127的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Java中运行一个简单的程序:





当我运行该代码的编译后,我面对这个结果:



变量 z 的编号与正确的unicode值不匹配!



我的所有偏好设置为UTF-8,在编辑器中也在我的终端,但我找不到一种方法来解决这个问题! >

更新:



同样在这里编写和编译程序:



提前感谢!

解决方案

使用以下Java程序:

 code> / * A.java * / 
class A
{
public static void main(String [] args)
{
for(char c ='A'; c <270; c ++)
{
System.out.print(c);
}
System.out.println();
}
}

然后我得到以下输出:

  $ java -Dfile.encoding = ASCII A 
默认字符集:US-ASCII
abcdefghijklmnopqrstuvwxyz {|}〜?? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ????????????????????????????????????????
$ java -Dfile.encoding = iso-8859-1 A
默认字符集:ISO-8859-1
abcdefghijklmnopqrstuvwxyz {|}〜 ??????????????
$ java -Dfile.encoding = UTF-8 A
默认字符集:UTF-8
abcdefghijklmnopqrstuvwxyz {|}〜¡¢¤¡¡¡¡ ²³'μ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČč
$ Java中的
默认字符集:UTF-8
ABCDEFGHIJKLMNOPQRSTUVWXYZ {|}〜¡¢£¤¥|§¨© ª«¬®¯±²³'μ¶·¸¹º»¼½¾ÁÁÄÄÖÖÖÖÖÖ÷÷÷÷÷ČččččččččččččČČČČČČ>>>>>>>>>>>>>>>>>>>>>>>>>>>> >从上面可以看出,ISO-8859-1打印 和?。 表示无效UTF-8,终端无法打印,?表示Java无法将所需字符转换为该字符集。这就是为什么ASCII只有'?',因为它只能转换ASCII字符。



默认的file.encoding是从你的语言环境中获取的,这就是为什么你可以需要设置您的LC_CTYPE。否则,您的终端需要设置为了解UTF-8。

  $ echo $ LC_CTYPE 
UTF-8


Actually I'm having some trouble with the display encoding in my terminal window on mac.

I'm running a simple program in Java:

And after the compiling when i run that code I face with this result:

The number of the variable z do not match the exact unicode value!

All my preferences are set to UTF-8, in the editor and also in my terminal, but I can't find a way to solve this problem!

UPDATE:

Also here the writing and the compiling of the program:

Thanks in advance!

解决方案

Using the following Java program:

/* A.java */
class A
{
  public static void main (String[] args)
  {
    for (char c = 'A'; c < 270; c++)
    {
      System.out.print(c);
    }
    System.out.println();
  }
}

then I get the following output:

 $ java -Dfile.encoding=ASCII A
 Default Charset: US-ASCII
 abcdefghijklmnopqrstuvwxyz{|}~??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
 $ java -Dfile.encoding=iso-8859-1 A
 Default Charset: ISO-8859-1
 abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������??????????????
 $ java -Dfile.encoding=UTF-8 A
 Default Charset: UTF-8
 abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČč
 $ java A
 Default Charset: UTF-8
 abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČč

From the above you can see that ISO-8859-1 prints both '�' and '?'. The '�' means that it was not valid UTF-8, and the terminal could not print it, and the '?' means that Java could not convert the required character into that character set. This is why ASCII only has '?', as it can only convert ASCII characters.

The default file.encoding is taken from from your locale, which is why you may need to set your LC_CTYPE. Otherwise, your terminal needs to be set to understand UTF-8.

$ echo $LC_CTYPE
UTF-8

这篇关于终端Mac的麻烦(ENCODING) - 不显示来自Java的字符&gt; 127的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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