简体   繁体   中英

RandomAccessFile java

RandomAccessFile has great advantages when i want to reach a certain byte in file in order to read/write to it.

on the other hand, i've noticed the following behavior: let's say i wanna save some data on the byte number 1,000,000,000 and it's the first time i'm writing to the file, it's making my file size hugh (1GB actually) for saving just one number and it's creation takes a few seconds (about 20 from my tests). i've also noticed that it initializes all the values that come before the byte 1,000,000,000 to 0 which means it iterates on all the preceeding bytes until it gets to the 1,000,000,000th byte.

is there any way to prevent from that behavior and just to write to the specific byte i want to reach?

I don't know what exactly you are trying to achieve, but the answer is no, there is any way to do that. When you say that you are saving just on number, in fact this is what you(human) see, but not the computer. To reach de 1,000,000,000 byte the computer have to know all the 1,000,000,000 bytes.

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