简体   繁体   English

Java Unix字符编码

[英]Java Unix character encoding

I'm running my Java program from Unix. 我正在从Unix运行我的Java程序。 To simplify matters, I describe only the relevant part. 为了简化问题,我仅描述相关部分。

public static void main(String[] args) {  
    System.out.println("féminin");  
} 

My output is garbage. 我的输出是垃圾。 It is obviously a character-encoding problem, the French character é is not showing up correctly. 显然这是一个字符编码问题,法语字符é无法正确显示。 I've tried the following: 我尝试了以下方法:

public static void main(String[] args) {  
    PrintStream ps = new PrintStream(System.out, true, "ISO-8859-1");  
    ps.println("féminin");  
} 

But my output is still showing ? 但是我的输出仍然显示吗? in palce of french character. 在法国人物的地方。
I ran the sam efile in command prompt with java -Dfile.encoding=IBM437 DSIClient féminin 我使用java -Dfile.encoding=IBM437 DSIClient féminin在命令提示符下运行了sam efile
it worked fine. 工作正常。 But How can I resolve this character-encoding issue with Unix? 但是,如何解决Unix的字符编码问题? Thanks 谢谢

The problem is most likely that your code editor and your terminal emulator use different encodings, and Java's notion of the default encoding may in addition be different. 问题很可能是您的代码编辑器和终端仿真器使用了不同的编码,并且Java的默认编码概念也可能有所不同。

To see if your terminal and your editor agree, you could simply cat your java source file. 要看到,如果你的终端和编辑器同意,你可以简单地cat Java源文件。 Does the é show up correctly? é是否正确显示? If so, you use the same encoding in your source code editor and your terminal, but it is not Java's default encoding. 如果是这样,则在源代码编辑器和终端中使用相同的编码,但这不是Java的默认编码。 If, OTOH, you can't see the é, you need to find out what encoding is used by your terminal and your editor and brind them in agreement. 如果在OTOH中看不到é,则需要找出终端和编辑器使用的编码并将它们绑定在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM