關(guān)于IO,我有兩個問題。答:在教程和一些 StackOverflow 答案中,他們聲稱FileInputStream沒有緩沖。真的嗎 ?以下代碼用于FileInputStream將數(shù)據(jù)讀入字節(jié)數(shù)組(1024 字節(jié))class Test { public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("./fos.txt"); FileOutputStream fos = new FileOutputStream("./copy.txt"); byte[] buffer = new byte[1024]; // Is this a buffer ? int len; while ((len = fis.read(buffer))!= -1) { fos.write(buffer); } fos.close(); fis.close(); }}從 API 中,有一行:public int read(byte b[]) 拋出 IOException@param b:讀取數(shù)據(jù)的緩沖區(qū)。B、如果都被緩沖了,都將數(shù)據(jù)放入緩沖區(qū),然后從緩沖區(qū)中取數(shù)據(jù),究竟是哪里BufferedInputStream比 快FileInputStream?謝謝
FileInputStream 沒有緩沖,為什么 BufferedInputStream 更快?
阿波羅的戰(zhàn)車
2021-10-27 16:57:59