Dark Horse programmer Java folder copy

Source: Internet
Author: User

-------------------- Android training, Java training, and hope to communicate with you! ----------------------

Package CN. itcst. copydir; import Java. io. *; public class copydirectory {public static void main (string [] ARGs) {copy ("D: \ workspace", "E: \ workspace"); system. out. println ("file copy completed! ");} Private Static void copy (string SRC, string des) {file file1 = new file (SRC); file [] FS = file1.listfiles (); file file2 = new file (DES); If (! File2.exists () {file2.mkdirs () ;}for (file F: FS) {If (F. isfile () {filecopy (F. getpath (), des + "\" + F. getname (); // call the object COPY method} else if (F. isdirectory () {copy (F. getpath (), des + "\" + F. getname () ;}}/ *** file copy method */Private Static void filecopy (string sourcepath, string despath) {bufferedinputstream bufin = NULL; bufferedoutputstream bufout = NULL; try {bufin = new bufferedinputstream (New fileinputstr EAM (sourcepath); bufout = new bufferedoutputstream (New fileoutputstream (despath); int length = 0; while (length = bufin. Read ())! =-1) {bufout. write (length) ;}} catch (ioexception e) {e. printstacktrace ();} finally {try {bufin. close (); bufout. close ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();}}}}

 

----------------------
Android training and Java training. We look forward to communicating with you! ----------------------

 

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.