FileInputStream.skip() 是否进行查找?
我想将一个可能很大的文件的最后 10MB 复制到另一个文件中。理想情况下,我会使用 FileInputStream、skip(),然后 read()。但是我不确定skip()的性能是否会很差。 Skip() 通常是使用下面的文件查找来实现的,还是实际上读取并丢弃数据?
我知道 RandomAccessFile 但我感兴趣的是我是否可以使用 FileInputStream 来代替它(RandomAccessFile 很烦人,因为 API 是非标准的)。
I want to copy the last 10MB of a possibly large file into another file. Ideally I would use FileInputStream, skip() and then read(). However I'm unsure if the performance of skip() will be bad. Is skip() typically implemented using a file seek underneath or does it actually read and discard data?
I know about RandomAccessFile but I'm interested in whether I could use FileInputStream in place of that (RandomAccessFile is annoying as the API is non-standard).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你会对这个 LINK 感兴趣,
它说要寻求比跳过更快
you will be interested with this LINK
it say that seek is faster than skip
取决于您的 JVM,但这是最近 openjdk 的
FileInputStream.skip()
的源代码:看起来它正在执行
seek()
。但是,我不明白为什么RandomAccessFile
是非标准的。它是java.io
包的一部分,从 1.0 开始就存在。Depends on your JVM, but here's the source for
FileInputStream.skip()
for a recent openjdk:Looks like it's doing a
seek()
. However, I don't see whyRandomAccessFile
is non-standard. It's part of thejava.io
package and has been since 1.0.