IO流之位元組字元緩衝流

2021-08-22 19:46:39 字數 916 閱讀 7413

io裡面的緩衝流分,位元組緩衝流和字元緩衝流。

位元組緩衝流:new bufferedinputstream( new fileinputstream(srcfile) )

new bufferedoutputstream( new fileoutputstream(destfile) );

位元組緩衝流沒有別的新加的方法,用的時候最好加上,據說加上了效能好一些。

字元緩衝流:bufferedreader = new bufferedreader(reader);

bufferedwriter = new bufferedwriter(writer);

字元緩衝流,reader 加了 readline() 方法

writer 加了 newline() 方法

1.位元組緩衝流實現複製檔案

/**

* 拷貝檔案

* @param srcfile 原始檔的file物件

* @param destfile 目標檔案的file物件

*/public static void copyfile(file srcfile, file destfile)

os.flush();

} catch (exception e) finally catch (ioexception e)

try catch (ioexception e)

} }

2.字元緩衝流實現讀寫檔案(存字元檔案)

public static void copyfile(file srcfile, file destfile) 

bufferedwriter.flush();

//關閉流...

} catch (exception e)

}

IO流 位元組緩衝流,字元緩衝流

處理流 裝飾流 位元組緩衝流,字元緩衝流 用於提高位元組流的效能 bufferedinputstream,bufferedoutputstream 位元組緩衝流 bufferedinputstream is newbufferedinputstream new fileinputstream fil...

IO流 位元組流,字元流,緩衝流

一 io流的分類 組織架構 這麼龐大的體系裡面,常用的就那麼幾個,我們把它們抽取出來,如下圖 二 字元位元組,輸入輸出流的概念 字元流的由來 因為資料編碼的不同,而有了對字元進行高效操作的流物件。本質其實就是基於位元組流讀取時,去查了指定的碼表。位元組流和字元流的區別 結論 只要是處理純文字資料,就...

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

位元組讀流 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...