简体   繁体   中英

RandomAccessFile: write(byte) in a loop or write(byte array), whats more effiecient?

I am wondring what is more efficient should I use a for loop that invokes write with each byte x times, or I should have an array that will contain my data and write it with write(byte array)? Basically the question is write(byte array) more efficient than subsquent calls for write(byte) in a loop. I am programing in java and using RandomAccessFile.

Writing a byte array is always going to be quicker than repeated calls to write one byte at a time. There's much less overhead (method calls, IO).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM