Increase Internal Buffer Size Used by Java FileInputStream
When calling read(byte[])
on a FileInputStream
, the read size is always 8k, even if byte[]
is exponentially large.
How do you increase the max read amount returned per call?
Please do not suggest a metho开发者_运维百科d that merely masks the limitation of FileInputStream
.
Update: There doesn't seem to be a real solution to this. However, I calculated the method call overhead to about 226uS on my system, for 1G file. It's probably safe to say this is not going to impact the performance in any real way.
Wrap it in a BufferedInputStream which allows you to specify the buffer size.
You could try to memory map the file by using NIO, but I'm not sure what the problem with 8K is. You can either copy the 8K to your bigger array or use the returned length to call
public int read(byte[] b,
int off,
int len)
throws IOException
With off being the return value from the last read.
The size of each read you see might be the buffer size used by the operating system itself. So you might have to make a change at the OS level. How you do that would be system dependent. You might be able to specify the block size when creating the file system. This has traditionally been possible for Unix filesystems. Although ironically I believe the feature was used to have smaller blocks for filesystems expected to have many small files.
精彩评论