changing JVM encoding; setting -Dfile.encoding doesn't work

P

pasmol

Hi,

I need to setup default encoding for jBoss/Tomcat. I tried to use
file.encoding property,
but it doesn't work.

I wrote simple test:

public class Test {
public static void main(String[] args) {
System.out.println(sun.io.Converters.getDefaultEncodingName());
System.out.println(System.getProperty("file.encoding"));
}
}

.... and run it in two different environments:

1) Win2KProPL

C:\TEMP>java -version
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

C:\TEMP>javac Test.java

C:\TEMP>java Test
Cp1250
Cp1250

C:\TEMP>java -Dfile.encoding=ISO8859_2 Test
Cp1250
ISO8859_2

2) RedHat9

[root@stefan share]# java -version
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
[root@stefan share]# javac Test.java
[root@stefan share]# java Test
UTF-8
UTF-8
[root@stefan share]# java -Dfile.encoding=ISO8859_2 Test
UTF-8
ISO8859_2

I tried also other names (iso-8859-2, 8859_2, etc.), but with the same
result.

Does anyone know the reason for ignoring file.encoding?

I debugged SCSL sources of sun.io.Converters, and it seems that
file.encoding must
have been set before.

public static String getDefaultEncodingName() {
synchronized (lock) {
if (defaultEncoding == null) {
java.security.PrivilegedAction pa =
new sun.security.action.GetPropertyAction("file.encoding");
defaultEncoding =
(String)java.security.AccessController.doPrivileged(pa);
}
}
return defaultEncoding;
}

Any idea?

Thanks in advance,
Piotr Smolinski
 
R

Real Gagnon

(e-mail address removed) ([email protected]) wrote in
I need to setup default encoding for jBoss/Tomcat. I tried to use
file.encoding property,
but it doesn't work.

Maybe it's a bug with 1.4.2_05

Here with (WinXP)

public class Test {
public static void main(String[] args) {
System.out.println(sun.io.Converters.getDefaultEncodingName());
System.out.println(System.getProperty("file.encoding"));
System.out.println("é à ê");
}
}

the output is

Java Test
Cp1252
Cp1252
Ú Ó Û
Java -Dfile.encoding=Cp850 Test
Cp850
Cp850
é à ê
java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top