[an error occurred while processing this directive]

Java get default Charset

                         

We can achieve the default charset through the java program. In our example java program we have created an object of FileWriter and then we will be using getEncoding() method for getting the default charset of this file writer. For windows system it is by default set to the value Cp1252.

Here is the full example code of GetDefaultCharset.java as follows:

 

GetDefaultCharset.java 

import java.io.*;

    public class GetDefaultCharset {
        public static void main(String args[]) 
            throws IOException {
            FileWriter filewrt = new FileWriter("out");
            String defaultcharset = filewrt.getEncoding();
            filewrt.close();
            System.out.println("Default encoding is :"+defaultcharset);
        }
    }

Output:

C:\javaexamples>javac GetDefaultCharset.java

C:\javaexamples>java GetDefaultCharset
Default encoding is : Cp1252

C:\javaexamples>

Download Source Code

                         

[an error occurred while processing this directive]