File Operation Functions

Source: Internet
Author: User

1. File Replication

Private Static void copy (file [] S, file D) <br/>{< br/> If (! D. exists () <br/>{< br/> D. mkdir (); <br/>}< br/> for (INT I = 0; I <S. length; I ++) <br/>{< br/> If (s [I]. isfile () <br/>{< br/> try {<br/> fileinputstream FD = new fileinputstream (s [I]); <br/> fileoutputstream out = new fileoutputstream (new file (D. getpath () + file. separator + s [I]. getname (); <br/> int COUNT = FCM. available (); <br/> byte [] DATA = new byte [count]; <br/> If (FCM. read (data ))! =-1) {<br/> out. write (data); // copy the file content <br/>}< br/> out. close (); <br/> FCM. close (); <br/>}catch (exception e) <br/>{< br/> E. printstacktrace (); <br/>}< br/> If (s [I]. isdirectory () <br/>{< br/> file des = new file (D. getpath () + file. separator + s [I]. getname (); <br/> des. mkdir (); // create the same folder in the target folder <br/> copy (s [I]. listfiles (), des); // recursive call method <br/>}< br/>} 

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.