Home Java Java-get-example Java get default Charset
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java get default Charset

Advertisement
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.

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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Related Tutorials

Ask Questions?    Discuss: Java get default Charset  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com