This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: get set default Character encoding Charset in Java
Feed Title: Javarevisited Blog
Feed URL: http://javarevisited.blogspot.com/feeds/posts/default?alt=rss
Feed Description: Blog on Java, Unix, Linux, FIX Protocol technology. I share my experience as tutorial, article, interview questions, programming, design etc.
How to get and set default Character encoding or Charset in Java
Default Character encoding in Javaor charset is the character encoding used by JVM to convert bytes into Strings or chaaracters when youdon't define java system property "file.encoding". Java gets character encoding by calling System.getProperty("file.encoding","UTF-8") at the time of JVM startup. So if Java doesn't get any file.encoding attribute it uses "UTF-8" character encoding for all practical purpuse e.g. on String.getBytes() or Charset.defaultCharSet().
Most important pointto remeber is that Java caches character encoding or value of system property "file.encoding" in most of its core classes like InputStreamReader which needs character encoding after JVM started. so if you change system property "file.encoding" programatically you don't see desired effect and that's why you should always work with your own character encoding provided to your application and if its need to be set than set character encoding or charset while you start JVM.In this Java tutorial we will see couple of different way by which we can set default character encoding or charset of Java and how toretrieve value of charset inside java program.