How to find character encodings supported in Java SE

Run this code to find all available character encodings supported by your current JVM. If you have text in some encoding which is not present in this list, you will end up showing messed up values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SortedMap m = Charset.availableCharsets();
	      Set k = m.keySet();
	      System.out.println("Canonical name, Display name,"
	         +" Can encode, Aliases");
	      Iterator i = k.iterator();
	      while (i.hasNext()) {
	         String n = (String) i.next();
	         Charset e = (Charset) m.get(n);
	         String d = e.displayName();
	         boolean c = e.canEncode();
	         System.out.print(n+", "+d+", "+c);
	         Set s = e.aliases();
	         Iterator j = s.iterator();
	         while (j.hasNext()) {
	            String a = (String) j.next();         
	            System.out.print(", "+a);
	         }
	         System.out.println("");
	      }

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *