Java file stream relocation, seek, Mark Reset.

Source: Internet
Author: User

Mark and reset operations for Java InputStream
Mark is used to mark the current position; FileInputStream does not support mark and reeset two functions;

But Bufferedinputstream supports this operation;

After the mark (READLIMIT) tag, subsequent calls to the Reset () function will bring the file stream back to mark's position for reuse.

If it's not mark, then you can't read it again after reading the end of the file.

Mark and reset should be used in conjunction.


FileInputStream infile = new FileInputStream ("test.txt");
Buffedfile = new Bufferedinputstream (infile);
Buffedfile.mark (available ());
Read to Buffedfile, after read

Buffedfile.reset ();

Then you can continue to use Buffedfile. Otherwise you won't be able to use it anymore. This program is equivalent to starting with the first offset of the file stream, of course, if you read n bytes, then mark, then next time you reset, start using the file stream from N.

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////

Similar to the C language seek usage.
Randomfile = new Randomaccessfile ("FileName", "RW");
Long filelength = Randomfile.length ();
Randomfile.seek (100);

Operates on a file stream starting at offset 100.

。。。。。。。。。。。。。。。。。


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.