简体   繁体   中英

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.

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?

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

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