简体   繁体   English

大文件的java.nio.channels.FileChannel.size()快速吗?

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

In javadoc this method is explained as: 在javadoc中,此方法解释为:

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. OpenJDK中FileChannel的实现使用fstat64GetFileSize来获取文件的大小。 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. 因此,可能存在JVM的实现,其中此方法的调用读取了整个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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