2

When I run a java application on "Linux CentOS 7"

Charset.defaultCharset() is returning "US-ASCII".

If I pass the JVM argument -Dfile.encoding="UTF-8" I am able to change the character set to UTF-8.

But my question is how does the default character set get initialized if no parameter is set at JVM at startup.

It must be from the OS Locale or some similar setting. How do I determine which OS setting it is that gets read by the JVM?

Nick
  • 629
  • 1
  • 6
  • 9
  • 3
    JDK [parses](http://hg.openjdk.java.net/jdk-updates/jdk11u/file/a5cedc08db03/src/java.base/unix/native/libjava/java_props_md.c#l93) whatever standard [`setlocale`](http://man7.org/linux/man-pages/man3/setlocale.3.html) call returns. – apangin Jun 05 '19 at 22:19
  • Stepping back from the question, do you really need to use the computer's user's current default character encoding? It's either exactly the adaptability that you need or an indeterminism that you should stay away from. – Tom Blodget Jun 05 '19 at 22:45
  • I don't need to use the computer's user's current default and I definitely shouldn't. I'm just trying to debug and understand what's going on in that environment. – Nick Jun 06 '19 at 00:52
  • On CentOS the system default is probably determined by /etc/locale.conf (see https://www.rosehosting.com/blog/how-to-set-up-system-locale-on-centos-7/), but I didn't have the opportunity to check. This also seems to be distribution specific (on Red Hat, it's in /etc/sysconfig/i18n). – Attila Csipak Nov 05 '19 at 08:48

0 Answers0