BufferedReader与BufferedWriter读写中文乱码问题

正常读写英文时用“”“”没问题

FileReader fre = new FileReader("E:\\TEST\\readText.txt");  
FileWriter fwi = new FileWriter("E:\\TEST\\readText2.txt");  

BufferedReader bufr = new BufferedReader(fre ); 
BufferedWriter bufw = new BufferedWriter(fwi );  

String line = null;  
while((line = bufr.readLine()) != null){  
    bufw.write(line); 
    bufw.newLine();  
    bufw.flush();  
} 
bufr.close();  
bufw.close();  

  

读取中文时需要用GBK,否则会出现乱码

File fileIn= new File("E:\\TEST\\readText.txt");
File fileOut= new File("E:\\TEST\\readText2.txt");

InputStreamReader inStream = new InputStreamReader(new FileInputStream(fileIn), "GBK");

OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(fileOut),"GBK");

BufferedReader reader = new BufferedReader(inStream);
BufferedWriter writer = new BufferedWriter(writerStream);
String lineWriter = null;
while ((lineWriter = reader.readLine()) != null) {
    writer.write(lineWriter);
    writer.newLine(); 
    writer.flush(); 
}
reader.close(); 
writer.close();

  

posted @ 2016-12-14 11:07  我滴个神呐  阅读(12895)  评论(0编辑  收藏  举报