I have a question about buffer size in Java. Why do we set the buffer size to 1024or 2^n. For example:
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();
How does it work outputStream.write(bytes, 0, read);? Why do we use an array bytes?
source
share