Get the default character set of the JVM

public class Hello {
 public static void main(String args[]) throws Exception{
  // not crossplateform safe
  System.out.println(System.getProperty("file.encoding"));
  // jdk1.4
  System.out.println(
     new java.io.OutputStreamWriter(
        new java.io.ByteArrayOutputStream()).getEncoding()
     );
  // jdk1.5
  System.out.println(java.nio.charset.Charset.defaultCharset().name());
  }
}
Output example (winXP)
>java Hello
Cp1252
Cp1252
windows-1252
See also java encoding table for the encoding sets supported.


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2010
[ home ]