我對Java中的緩衝區大小有一些疑問。爲什麼我們將緩衝區大小設置爲1024
或2^n
。例如:Java中的緩衝區大小
inputStream = file.getInputStream();
File newFile = new File("C:/uploads/operators.xml");
outputStream = new FileOutputStream(newFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
outputStream.close();
inputStream.close();
outputStream.write(bytes, 0, read);
如何工作?爲什麼我們使用bytes
數組?
但爲什麼'2^n'?爲什麼不只是'1000'? – Tony
@Tony因爲[1024字節== 1千字節](http://pc.net/helpcenter/answers/why_1024_bytes)。 –
那麼我們爲什麼要使用千字節? – Tony