4

from where java extract the default encoding ?

I tried the following code on 2 plateforms : redhat 4 and centos 5

public class EncodingTest {
    public static void main(String args[]) throws Exception{
    System.out.println(System.getProperty("file.encoding"));
    System.out.println(
               new java.io.OutputStreamWriter(
                              new java.io.ByteArrayOutputStream()).getEncoding()
               );
    }
}

I have two different results,redhat UTF-8 and for centos ASCII. It's the same java installation and version (1.4). I launch java without parameter -Dfile.encoding.

Thanks.

La Chamelle
  • 2,927
  • 4
  • 36
  • 54
  • See [this question](http://stackoverflow.com/questions/1749064/how-to-find-default-charset-encoding-in-java) - it describes a bug that may affect you. – finnw Oct 25 '11 at 16:12

1 Answers1

2

The default platform charset is taken from the OS and depends on the default locale. If you get different results on different machines these machines have different default locale. Now it depends on your needs. If you wish your application to work exactly the same way on all platform pass charset using -Dfile.encoding

Renaud
  • 16,073
  • 6
  • 81
  • 79
AlexR
  • 114,158
  • 16
  • 130
  • 208