简体   繁体   English

在Java下定义不同平台中的重音字符

[英]Defining accent characters in different platforms under java

I have a problem with the accent character in different platforms. 我在不同平台上的重音符号存在问题。

When I log this in my machine under fedora (where default charset is UTF-8) it is printing correvtly as Sacré Coeur. 当我在fedora下(默认字符集为UTF-8)在我的机器上登录时,它正正确地打印为SacréCoeur

But when i update to another server that is running on RedHat (where default charset is ISO-8859-1), it is printing as Sacré Coeur. 但是,当我更新到在RedHat (默认字符集为ISO-8859-1)上运行的另一台服务器时,它将打印为SacréCoeur。

I want to log it in RedHat server as same as in my my Fedora machine. 我想像在我的Fedora机器中一样在RedHat服务器中记录它。 How can I do this? 我怎样才能做到这一点?

My Workout : 我的锻炼:

  • I tried to changes the System.setProperty("file.encoding", "ISO-8859-1"); 我试图更改System.setProperty(“ file.encoding”,“ ISO-8859-1”); in local with the purpouse of doing the reverse version System.setProperty("file.encoding", "UTF-8"); 在本地,目的是进行反向版本System.setProperty(“ file.encoding”,“ UTF-8”); in the RedHat Server, if it change the way of logging in the local. 在RedHat Server中,如果它更改了本地登录方式。 But nothing changed. 但是什么都没有改变。
  • I noticed there are couple of threads regarding the accent character but nithing answers me. 我注意到有几个关于重音符号的主题,但是没有什么能回答我的。 That's why I asked a new question. 这就是为什么我问一个新问题。
  • I tried this one as well but not working. 我也尝试过这个 ,但是没有用。

    System.setProperty("file.encoding","ISO-8859-1"); Field charset =Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null,null);

  • But I didn't try to set the charset at the JVM start. 但是我没有尝试在JVM启动时设置字符集。 If it will works please explain me how can I do it? 如果可以,请向我解释我该怎么做?

To get similar out put from all the environments, with out depending on the server OS default character encoding, when you start your program or the server environment (Jboss tomcat or jetty) pass -Dfile.encoding to the start-up script 为了从所有环境中获得类似的输出,而没有依赖于服务器操作系统的默认字符编码,在启动程序或服务器环境(Jboss tomcat或jetty)时,将-Dfile.encoding传递给启动脚本

(lets say run.sh in jboss, add -Dfile.encoding=UTF-8 to JAVA_OPTS) (在jboss中说run.sh,将-Dfile.encoding = UTF-8添加到JAVA_OPTS)

-Dfile.encoding=UTF-8 -Dfile.encoding = UTF-8

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

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