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 Recent java Faqs
- How to uncompress a file in the gzip format?
- How to make a gzip file in Java?
- How to use Java String.split method to split a string by dot?
- How to validate URL in Java?
- How to schedule a job in Java?
- How to return the content in the correct encoding from a servlet?
- What is the difference between JDK and JRE?
Most Viewed java Faqs
- How to read input from console (keyboard) in Java?
- How to use HttpURLConnection POST data to web server?
- How to add BASIC Authentication into HttpURLConnection?
- How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?
- What are class variables in Java?
- What are local variables in Java?
- How to Use Updatable ResultSet in JDBC?