Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

XyzWs Java FAQ:
How to get default character set for the Java virtual machine?


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
Advertisement
XyzWs Java FAQ: How to get default character set for the Java virtual machine?

How to get default character set for the Java virtual machine?


Every instance of the Java virtual machine has a default charset, which may or may not be one of the standard charsets. The default charset is determined during virtual-machine startup and typically depends upon the locale and charset being used by the underlying operating system.

In Java 5.0, the java.nio.charset class provides a static method, called the defaultCharset(), to retrieve the default charset.

  ...
  public static void main(String[] args) {
      Charset dfset = Charset.defaultCharset();
      out.println(dfset.name());
  }
  ...

In the previous version of Java (JDK 1.4), you can get it from the getEncoding() methods of the InputStreamReader and OutputStreamWriter classes. The method returns the name of the character encoding being used. If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned.


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Support  | Feedback  | Help