简体   繁体   中英

Is java.nio.channels.FileChannel.size() fast for big files?

In javadoc this method is explained as:

Returns: The current size of this channel's file, measured in bytes

I need to ask if this method call actually results in reading/consuming somehow the whole content of the file or not? In other words, if this method call is very fast and cheap or depends on the file' size?

Implementation of FileChannel in OpenJDK uses fstat64 or GetFileSize to get size of the file. It is very fast.

But it is not required by specification that this method run in constant time. So there may be implementations of JVM where call of this method reads entire file.

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