2012-12-14 100 views
-2

可能重複在另一個文件中寫:
Read special symbols from file從文件中讀取特殊字符和使用Java

我試圖將文件複製到另一個文件。該文件使用編碼標準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

嗯...你是否嘗試設置編碼也**和OutputStreamWriter **? – Andremoniy

+0

這裏有很多右括號。要寫一個讀取行,你必須知道它是什麼,你正在失去'br.readLine()'返回的內容。 – jlordo

回答

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

或者Java 7中使用Files.copy

+0

在FileOutputStream構造函數中給出了UTF8,但仍然是相同的結果 –

+0

在OutputStreamWriter中我想。嘗試使用[JEdit](http://www.jedit.org/)左右來檢查原始文件。 –

+0

@JoopEggen如何在Files.copy中設置編碼? –

相關問題