Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a Java program on Mac OS X 10.8 (from the Terminal), and the Java VM's file.encoding is defaulting to "SJIS". I even tried a tiny Java program that does nothing but print out the system properties, and that shows that the Java VM itself is defaulting to SJIS. (And let's face it, nobody likes SJIS!)

My terminal is set to UTF-8. My $LANG isn't set, and $LC_CTYPE is "UTF-8". No environmental variable or Terminal setting has "JIS" in it anywhere, AFAICT.

On Java on Mac OS X, where does it get the file.encoding value from? Is there a system setting I can change so that it uses UTF-8? I don't want to have to specify this per-application and per-library, because that is somewhere between "awkward" and "impossible", depending on the program.

I suppose I'm OK with setting an environmental variable for this, but I can't find any standard variables (like $LANG) that affect Java.

share|improve this question

You could always put this code into a java class in your favorite IDE

import java.nio.charset.Charset;

Then follow defaultCharset() link to understand how your JVM instance will get determine default charset. Example on win 64b hotspot JVM jdk 1.7 :

 * Returns the default charset of this Java virtual machine.
 * <p> The default charset is determined during virtual-machine startup and
 * typically depends upon the locale and charset of the underlying
 * operating system.
 * @return  A charset object for the default charset
 * @since 1.5
public static Charset defaultCharset() {
    if (defaultCharset == null) {
        synchronized (Charset.class) {
            String csn = AccessController.doPrivileged(
                new GetPropertyAction("file.encoding"));
            Charset cs = lookup(csn);
            if (cs != null)
                defaultCharset = cs;
                defaultCharset = forName("UTF-8");
    return defaultCharset;

As you know, you could always set file.encoding at startup..

java -Dfile.encoding=UTF-8 MyClass

In your case, SJIS seems refer to a Japan encoding (MS Japan OS src) ? I mean SJIS could be default value when LANG=ja_JP.PCK (src)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.