简体   繁体   中英

How setLength to RandomAccessFile without write it?

I am running the following piece of code:

    RandomAccessFile randomAccessFile = new RandomAccessFile(new File(Download.DESTINATION + Download.getFileName(Download.FILEPATH)), "rwd");
    randomAccessFile.setLength(contentLength);
    randomAccessFile.close();

A contentLength is about 60Gb. And I expect that this space will be just created on hard drive. This operation should be just byte allocation and cost nothing. I mean that file system just marks that these space is reserved by file. But java writes something to this file:

在此处输入图片说明

Is there a way to disable this? I do not care what file contains right now. All data will be rewritten later. Why java fills this file immediatelly?

PS if question is unclear feel free to ask questions in comments.

randomAccessFile.setLength(1024l * 1024 * 1024 * 60);

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