CharsetDemo.java
Download CharsetDemo.java
1: // This demo show the default text file encoding (a.k.a "Charset") for the
2: // currently running JRE. It then shows the aliases for "UTF-8", followed by
3: // the complete list of Charsets supported by the currently running JRE.
4: //
5: // Written 3/2021 by Wayne Pollock, Tampa Florida USA
6:
7: import java.nio.charset.*;
8: import java.util.Arrays;
9:
10: public class CharsetDemo {
11: public static void main ( String[] args ) {
12: System.out.println(
13: "Default JRE Charset: " + Charset.defaultCharset() );
14:
15: System.out.println( "UTF-8 Canonical Name: "
16: + StandardCharsets.UTF_8.name() );
17: System.out.println( "Aliases for UTF-8: " +
18: Arrays.toString(
19: StandardCharsets.UTF_8.aliases().toArray( new String[0] ) )
20: );
21:
22: System.out.println("\nAvailable Charsets in this Java implementation:" );
23: Charset.availableCharsets().forEach(
24: (key, value) -> { System.out.println( key ); }
25: );
26: }
27: }