String Data_Path = "D:/file_jiucool.txt ";
File file = new File (Data_Path );
String line = "";
If (file. exists ()){
FileReader reader = new FileReader (Data_Path );
BufferedReader bufferedreader = new BufferedReader (reader );
While (line = bufferedreader. readLine ())! = Null ){
Line = new String (line. getBytes (), "UTF-8 ");
System. out. println (line );
}
}
In the above Code, set to GBK, GB2312 all for garbled characters, set to UTF-8, the last Chinese character for garbled characters, is not very depressing? The correct code is as follows:
String Data_Path = "D:/file_jiucool.txt ";
File file = new File (Data_Path );
String line = "";
If (file. exists ()){
// FileReader reader = new FileReader (Data_Path );
// BufferedReader bufferedreader = new BufferedReader (reader );
InputStreamReader isr = new InputStreamReader (new FileInputStream (file), "UTF-8 ");
BufferedReader bufferedreader = new BufferedReader (isr );
While (line = bufferedreader. readLine ())! = Null ){
// Line = new String (line. getBytes (), "UTF-8 ");
System. out. println (line );
}
}
Therefore, you must set the encoding when reading the file, instead of setting the encoding when reading the file output!