解決亂碼 自定義io流讀寫編碼,讀寫不同編碼的檔案

2021-08-28 07:04:36 字數 598 閱讀 1078

利用io流讀寫檔案時,預設的流編碼都是utf-8,d但是如果流的編碼和檔案的編碼不一樣,得到的內容是亂碼.所幸的是位元組流可以在轉為string使用new string(byte,charset)設定編碼.字元流inputstreamreader,outputstreamwriter這兩個類的構造方法提供了設定流編碼的方法.

下面舉個簡單的例子,其他情況可以舉一反三.

@test

public void test4()

sb = new stringbuilder();

bufferedwriter.write(sb.tostring());

bufferedwriter.flush();

} }catch (exception e) ", e);

} finally catch (ioexception e) ", e);}}

if (bufferedreader != null) catch (ioexception e) ", e);}}

}}private string getstatus(string s)

return "020";

}

自定義非同步IO

一 http請求本質阻塞 import socket import select client socket.socket client.connect www.baidu.com 80 io阻塞 print 鏈結成功 data client.recv 1024 io阻塞 print data 二 ...

自定義瀑布流

在.h裡 class,在.m裡 import class dkflowlayout protocol dkflowlayoutdelegate cgfloat layout dkflowlayout layout heightforitematindexpath nsindexpath indexp...

自定義非同步IO框架

非同步就是 非同步 非阻塞 迴圈 select只能完成io多路復用,不能完成非同步 io多路復用 監聽多個socket物件,這個過程是同步的 利用其特性可以開發非同步模組 非同步io 非阻塞的socket io多路復用 自定義非同步框架 deffileno self select監聽的物件,只要內部...