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 avoid an java.util.ConcurrentModificationException with ArrayList?
- How to convert a given array to a list in Java?
- How to make Java objects eligible for garbage collection?
- What are local variables in Java?
- What are instance variables in Java?
- How many backslashes?
- What are class variables in Java?
Most Viewed java Faqs
- How to use HttpURLConnection POST data to web server?
- What is runtime polymorphism in Java?
- How to add BASIC Authentication into HttpURLConnection?
- What is String literal pool?
- Can the run() method be called directly to start a thread?
- What does Class.forname method do?
- How to read input from console (keyboard) in Java?