-------------------- 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! ----------------------