Use filechannel to copy files

Source: Internet
Author: User

The file channel defines two methods for direct file transfer:
Int transferto (INT position, Long Count, writablebytechannel DST );
This function transfers count bytes to the DST channel from position.
Int transferfrom (readablebytechannel SRC, long position, Long Count );
Transfers count bytes from the SRC channel to the file. position is the position where the file is written.
The channel obtained from fileinputstream only supports transferto, while the channel obtained from fileoutputstream only supports the tansferfrom () method.

    1. Filechannel SFC =NewFileinputstream ("D: // suqiang // from.txt"). getchannel ();
    2. Filechannel TFC =NewFileoutputstream ("D: // suqiang // to.txt"). getchannel ();
    3. SFC. transferto (0, SFC. Size (), TFC );
    4. SFC. Close ();
    5. TFC. Close ();

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.