位元組流PK字元流

2021-08-02 08:20:12 字數 552 閱讀 2547

位元組流:

頂層抽象類;inputstream outputstream

常用子類:

fileinputstream:從檔案讀入的輸入流

fileoutputstream:從檔案寫入的輸出流

字元流:

inputstreamreader:位元組流轉換為字元流

//讀取e盤下panda.txt的檔案中字元

inputstreamreader reader = new inputstreamreader(new fileinputstream(「e:/panda.txt」));

outputstreamwriter:位元組流轉換為字元流

outputstreamwriter writer = new outputstreamwriter(new fileoutputstream(「e:/panda.txt」));

string str = 「hello panda」;

writer.write(str);

writer.flush();

writer.close();

位元組流 字元流

fileoutputstream 構造 構造方法摘要 fileoutputstream file file 建立輸出流,不是以續寫方式關聯 fileoutputstream string name 建立輸出流,不是以續寫方式關聯 作用 1.建立乙個輸出流物件 2.如果你關聯的檔案,或者檔案的字串不存...

位元組流,字元流

在程式中所有的資料都是以流的方式進行傳輸或者儲存的,程式需要資料的時候需要使用輸入流讀取資料,而當程式需要將一些資料儲存起來的時候,就要使用輸出流。可以通過下面的輸入輸出流關係圖表示這種方式。位元組流 位元組流主要操作byte型別資料,以byte陣列為準,主要操作類是outputstream類和in...

位元組流 字元流 位元組緩衝流 字元緩衝流

位元組讀流 fileinputstream fis new fileinputstream file byte b new byte 1024 int len 0 while len fis.read b 1 字元讀流 filereader fr new filereader file char c...