Java Reference
In-Depth Information
Original Text:
My horse moved on; hoof after hoof
He raised, and never stopped:
When down behind the cottage roof,
At once, the bright moon dropped.
--------------------
Decoded Text:
My horse moved on; hoof after hoof
He raised, and never stopped:
When down behind the cottage roof,
At once, the bright moon dropped.
You can get the list of all available character sets supported by the JVM using the static method
availableCharsets() of the Charset class, which returns a Map . The key of the Map is a character set name and the
value is the Charset object that represents the character set.
You can create your own character encoder/decoder by using the CharsetProvider class in
java.nio.charset.spi package. You need to explore the java.nio.charset and java.nio.charset.spi packages for
details on how to create and install your own character set. this topic does not cover how to create and install a custom
character set.
Tip
Listing 9-6 demonstrates how to list all character sets supported by a JVM. A partial output is shown. When you
run the program, you may get a different output.
Listing 9-6. List of Available Character Sets Supported by Your JVM
// AvailableCharsets.java
package com.jdojo.nio;
import java.util.Map;
import java.nio.charset.Charset;
import java.util.Set;
public class AvailableCharsets {
public static void main(String[] args) {
Map<String, Charset> map = Charset.availableCharsets();
Set<String> keys = map.keySet();
System.out.println("Available Character Set Count: " + keys.size());
for(String charsetName : keys) {
System.out.println(charsetName);
}
}
}
 
Search WWH ::




Custom Search