可能重複在另一個文件中寫:
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();
}
嗯...你是否嘗試設置編碼也**和OutputStreamWriter **? – Andremoniy
這裏有很多右括號。要寫一個讀取行,你必須知道它是什麼,你正在失去'br.readLine()'返回的內容。 – jlordo