1. 程式人生 > >utf-8 讀入寫入檔案

utf-8 讀入寫入檔案

用下面的程式碼效果最好,親測!!!

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