示例

public static void main( String[] args ) {
// Assume default charset GB2312 and file with 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();
}
}



解决方案
要指定您自己的字符编码值,应对 FileInputStream 上的 CharsetDecoder 构造 InputStreamReader。

public static void main( String[] args ) {
// Assume default charset GB2312 and file with 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();
}

}