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.
Most Viewed java Faqs
- How to use HttpURLConnection POST data to web server?(15019)
- What is runtime polymorphism in Java?(9497)
- What is String literal pool?(8792)
- Can the run() method be called directly to start a thread?(8253)
- How to add BASIC Authentication into HttpURLConnection?(7483)
- Can transient variables be declared as 'final' or 'static'?(6303)
- Can static methods be overridden?(4965)
Most Recent java Faqs
- What is the difference between an enum type and java.lang.Enum?
- Which replace function works with regex?
- Why does TreeSet.add throw ClassCastException?
- What is variable hiding and shadowing?
- Can private method be overridden?
- How to enable JDBC tracing?
- How to Retrieve Automatically Generated Keys in JDBC?