Java buffer size

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?

+4
source share
2 answers

You read byte lengths bytes.lengthfrom a file stream and save them in an array of bytes bytes[]. And then you write bytes in the outputStreem array bytes[]. Read more the Java I of / About .

+1
source

, (, 512 ).

CPU L1. Intel 486 1K L1 , 1024. Pentium 8 L1, 8 * 1024.

4K, 64K L1 Cache, 64 * 1024 .

+1

Source: https://habr.com/ru/post/1526048/


All Articles