We are using the system property, file.encoding, to set the default character encoding for the JVM. On an English NT OS we start the Java process using -Dfile.encoding=UTF-8. This seems to work fine and sets the default encoding. But on a Japanese NT OS, it does not pick up the encoding setting. The following is a test java program I am using......
import java.io.PrintStream;
import sun.io.*;
import java.io.*;
public class TestEncoding {
public static void main(String argv[]) {
String encProperty = System.getProperty("file.encoding");
String byteToCharClass =
sun.io.ByteToCharConverter.getDefault().getClass().getName();
String charToByteClass =
sun.io.CharToByteConverter.getDefault().getClass().getName();
System.out.println("encProperty == '" + encProperty + "'");
System.out.println("Default ByteToChar Class == '" + byteToCharClass + "'");
System.out.println("Default CharToByte Class == '" + charToByteClass + "'");
ByteArrayOutputStream buf = new ByteArrayOutputStream(10);
OutputStreamWriter writer = new OutputStreamWriter(buf);
System.out.println("OutputStreamWriter encoding = " + writer.getEncoding());
}
}
When I run this from the English NT OS using
java -Dfile.encoding=UTF-8 TestEncoding
I get the following results:
encProperty == 'UTF-8'
Default ByteToChar Class == 'sun.io.ByteToCharUTF8'
Default CharToByte Class == 'sun.io.CharToByteUTF8'
OutputStreamWriter encoding = UTF8
BUT when I run it from a Japanese NT OS I get:
encProperty == 'MS932'
Default ByteToChar Class == 'sun.io.ByteToCharMS932'
Default CharToByte Class == 'sun.io.CharToByteMS932'
OutputStreamWriter encoding = MS932
Environment:
English NT 4.0 JDK1.2.2
Japanese NT 4.0 JDK1.2.2 and/or JDK1.3.1_01
Can anyone tell me why the results are different for the Japanese OS? Does anyone know of a workaround?