Příklad

public static void main( String[] args ) {
// Předpokládá se znaková sada ISO-8859-2 a soubor s obsahem UTF-16BE content
FileReader fileReader = null;
try {
fileReader = new java.io.FileReader( "file1" ); //$NON-NLS-1$
System.out.println( fileReader.read() );
} catch ( IOException e ) {
e.printStackTrace();
}
}



Řešení
Abyste mohli uvést hodnoty kódování znaků sami, vytvořte objekt InputStreamReader s pomocí CharsetDecoder v řetězci FileInputStream.

public static void main( String[] args ) {
// Předpokládá se znaková sada ISO-8859-2 a soubor s obsahem UTF-16BE content
InputStreamReader reader = null;
try {
reader = new InputStreamReader( new FileInputStream("file1"), "UTF-16BE");
System.out.println( reader.read() );
} catch ( IOException e ) {
e.printStackTrace();
}

}