Defining accent characters in different platforms under java

徘徊边缘 提交于 2019-12-25 02:55:14

问题


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.

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.

I want to log it in RedHat server as same as in my my Fedora machine. How can I do this?

My Workout :

  • I tried to changes the System.setProperty("file.encoding", "ISO-8859-1"); in local with the purpouse of doing the reverse version System.setProperty("file.encoding", "UTF-8"); in the RedHat Server, if it change the way of logging in the local. 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. If it will works please explain me how can I do it?

回答1:


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

(lets say run.sh in jboss, add -Dfile.encoding=UTF-8 to JAVA_OPTS)

-Dfile.encoding=UTF-8



来源:https://stackoverflow.com/questions/15236836/defining-accent-characters-in-different-platforms-under-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!