从文件中读取特殊字符并使用java在另一个文件中写入 [英] read special characters from a file and write in another file using java

查看:634
本文介绍了从文件中读取特殊字符并使用java在另一个文件中写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

从文件中读取特殊符号

我正在尝试复制一个文件到另一个文件。该文件使用编码标准UTF8
和文件也包含特殊字符。该程序无法以相同的格式复制另一个文件中的特殊字符,文件被
特殊符号的盒子形状打扰。

I am trying to copy a file to another file . The file is using encoding standard UTF8 and file also containing special characters . the program is not able to copy the special characters in another file in the same format the file is being disturbed with box shapes for special symbols.

 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();
  }


推荐答案

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

或者在java 7中使用文件.copy

Or in java 7 use Files.copy.

这篇关于从文件中读取特殊字符并使用java在另一个文件中写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆