从文件中读取特殊字符并使用java在另一个文件中写入

时间:2012-12-14 10:49:32

标签: java file input io output

  

可能重复:
  Read special symbols from file

我正在尝试将文件复制到另一个文件。该文件使用编码标准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();
  }

1 个答案:

答案 0 :(得分:0)

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

或者在java 7中使用Files.copy