本帖最后由 新航向 于 2014-9-1 20:47 编辑
“Demo_utf-8.txt”内容字符编码为UTF-8
已经通过“bw = new BufferedWriter(new OutputStreamWriter(System.out,"GBK"));”将编码转成GBK,为什么打印后仍为乱码?
如何解决?
向各位大神求教
- import java.io.*;
- class OutTest
- {
- public static void main(String[] args)
- {
- BufferedReader br = null;
- BufferedWriter bw = null;
- try
- {
- br = new BufferedReader(new FileReader("C:\\Users\\ZSG\\Desktop\Demo_utf-8.txt"));
- bw = new BufferedWriter(new OutputStreamWriter(System.out,"GBK"));
- String len = null;
- while ((len=br.readLine())!=null)
- {
- bw.write(len);
- bw.newLine();
- bw.flush();
- }
- }
- catch (IOException e)
- {
- System.out.println("复制失败");
- }
- finally
- {
- try
- {
- if(br!=null)
- br.close();
- }
- catch (IOException e)
- {
- }
- try
- {
- if(bw!=null)
- bw.close();
- }
- catch (IOException e)
- {
- }
- }
- }
- }
复制代码
|
|