private void FileReader () throws ioexception{
BufferedReader bf= New BufferedReader (New InputStreamReader (New FileInputStream ("d:\\comparedll.py"), "UTF-8");
String str= "";
while ((Str=bf.readline ())!=null) {
System.out.println (str);
}
Bf.close ();
}
If you do not specify the encoding, the system default encoding is used when reading the file, typically GBK
I/O class handling for Java
The reader class is the parent of the read characters in Java I/O, and the InputStream class is the parent class of the read Byte, and the InputStreamReader class is the association of byte-to-character bridges, which is responsible for processing read byte-to-character conversions during I/O processes. and the specific byte-to-character decoding implementation It is implemented by Streamdecoder, in the Streamdecoder decoding process must be specified by the user Charset encoding format. It is important to note that if you do not specify Charset, the default character set in the local environment will be used, such as GBK encoding in the Chinese environment.
Java Read file garbled