How do you determine the ideal buffer size when using FileInputStream?

后端 未结 9 1840
北海茫月
北海茫月 2020-11-22 17:01

I have a method that creates a MessageDigest (a hash) from a file, and I need to do this to a lot of files (>= 100,000). How big should I make the buffer used to read from t

9条回答
  •  一生所求
    2020-11-22 17:30

    In BufferedInputStream‘s source you will find: private static int DEFAULT_BUFFER_SIZE = 8192;
    So it's okey for you to use that default value.
    But if you can figure out some more information you will get more valueable answers.
    For example, your adsl maybe preffer a buffer of 1454 bytes, thats because TCP/IP's payload. For disks, you may use a value that match your disk's block size.

提交回复
热议问题