简体   繁体   English

如何随机获取文件的第n个文件段?

[英]How to get nth file segment of a file randomly?

I have a file, and I want to divide it in chunks of max_size = 1mb . 我有一个文件,我想将其分成max_size = 1mb块。

Now for example if I have a file - file.zip of size 10 MB , my file segments are file.zip.1, file.zip.2 . 现在,例如,如果我有一个大小为10 MB的文件-file.zip ,则我的文件段是file.zip.1,file.zip.2。 . . . file.zip.n file.zip.n

So given a n , can I directly retrieve file.zip.n ? 因此,给定n ,我可以直接检索file.zip.n吗?

Or in other words I dont want to loop through the entire file to get the nth file segment. 换句话说,我不想遍历整个文件来获取第n个文件段。 Is there any way by which I can get the iterator to the position in which the nth segment starts? 有什么方法可以使迭代器到达第n个分段的起始位置?

I have solved it! 我已经解决了!

Had to create an object RandomAccessFile class, and use the seek() method to skip required number of bytes. 必须创建一个对象RandomAccessFile类,并使用seek()方法跳过所需的字节数。

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

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