-2

可能重复:
从文件中读取特殊符号

我正在尝试将文件复制到另一个文件。该文件使用编码标准 UTF8 并且文件还包含特殊字符。该程序无法以相同格式复制另一个文件中的特殊字符,该文件被特殊符号的框形干扰。

 try 
  {
   BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File("path of the file")),"UTF8") ;
  BufferedWriter bw= new BufferedWriter(new OutputStreamReader(new FileOutputStream(new File("path of the output file");
    while(br.readLine()!=null)
   {
     //code here to read and write from a file to another.


    }

   }
  catch(Exception ex  
 { 
 ex.printStackTrace();
  }
4

1 回答 1

0
BufferedWriter bw = new BufferedWriter(
        new OutputStreamWriter(
            new FileOutputStream(new File("path of the output file")),
            "UTF-8"));

或者在 java 7 中使用Files.copy.

于 2012-12-14T10:52:50.857 回答