用OutputStreamWriter指定utf-8编码也会出现中文乱码,程序如下,请各位同学纠错,谢谢!!!
- <p> //用指定编码表复制一个有中文的.doc文件
- import java.io.*;
- class SetCodeSheet
- {
- public static void main(String[] args)
- {
- printDoc();//忘调用!!!
- }
- public static void printDoc()
- {
- BufferedReader fr=null;
- BufferedWriter fos=null;
- try
- {
- fr=new BufferedReader(new InputStreamReader(new FileInputStream("F:\\Film\\czvxuzrwzi66r6ru6ixipsu6_1.doc")));
- fos=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("new.doc"),"utf-8"));
- String line=null;
- while((line=fr.readLine())!=null)
- {
- fos.write(line);//易忘地方!!!忘传参数!!
- fos.newLine();
- fos.flush();
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("复制失败");
- }
- finally
- {
- if(fr!=null)
- try
- {
- fr.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("读取失败");
- }
- if(fos!=null)
- try
- {
- fos.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("输出失败");
- }
- }
- }
- }</p>
复制代码
|
|