utf-8 讀入寫入檔案
阿新 • • 發佈:2018-12-11
用下面的程式碼效果最好,親測!!!
FileInputStream fis = new FileInputStream(srcFile); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); BufferedReader br = new BufferedReader(isr); String line = null,FileContent=""; while ((line = br.readLine()) != null) { FileContent += line; FileContent += "\r\n"; // 補上換行符 } FileOutputStream fos = new FileOutputStream(toFile); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); osw.write(FileContent); osw.flush();