简体   繁体   中英

Java Unix character encoding

I'm running my Java program from Unix. 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
it worked fine. But How can I resolve this character-encoding issue with 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.

To see if your terminal and your editor agree, you could simply cat your java source file. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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