read special characters from a file and write in another file using java [duplicate]

江枫思渺然 提交于 2019-12-13 10:46:17

问题


Possible Duplicate:
Read special symbols from file

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

回答1:


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

Or in java 7 use Files.copy.



来源:https://stackoverflow.com/questions/13877187/read-special-characters-from-a-file-and-write-in-another-file-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!