1. 程式人生 > >Java 讀取寫入檔案亂碼問題解決

Java 讀取寫入檔案亂碼問題解決

Java 讀取寫入檔案亂碼問題解決

寫檔案

File f = new File(fileName);      
        if (!f.exists())   
        {       
            f.createNewFile();      
        }      
        OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f),"gbk");      
        BufferedWriter writer=
new BufferedWriter(write); writer.write(fileContent); writer.close();

讀檔案

File f = new File(fileName);      
        if(f.isFile()&&f.exists())  
        {       
            InputStreamReader read = new InputStreamReader(new FileInputStream(f),"gbk");       
            BufferedReader reader=
new BufferedReader(read); String line; while ((line = reader.readLine()) != null) { fileContent += line; } read.close();

作者:xiaosha_
來源:CSDN
原文:https://blog.csdn.net/xiaosha_/article/details/77566638


版權宣告:本文為博主原創文章,轉載請附上博文連結!

侵刪