Copy the C-drive folder to the D drive. Black Horse Programmer

Source: Internet
Author: User

classcopywenjianjia{ Public Static voidMain (string[] args)throwsException {//source FolderString yuan = "C:\\nimeizide"; //DestinationString Mudi = "D:\\nimeizide"; //set up a destination folder(NewFile (Mudi)). Mkdirs (); //get the current file or directory in the source folderfile[] Files = (NewFile (Yuan)). Listfiles ();  for(File file:files) {if(File.isdirectory ()) {String Yuandir= Yuan + "\ \" +File.getname (); String Mudidir= Mudi + "\ \" +File.getname (); //Copy Directorycopydir (Yuandir, Mudidir); }                        Else{copyFile (file,NewFile (Mudi + "\ \" +file.getname ())); }                }        }        //Copy Folder         Public Static voidCopydir (String yuandir, String mudidir)throwsException {(NewFile (Mudidir)). Mkdirs (); file[] Files= (NewFile (Yuandir)). Listfiles ();  for(File file:files) {if(File.isfile ()) {file Yuanfile= file;//source FileFile Mudifile =NewFile (NewFile (Mudidir). GetAbsolutePath () + "\ \" +file.getname ());                        CopyFile (Yuanfile, mudifile); }                        Else{String YuanJia= Yuandir + "\ \" +File.getname (); String Mudijia= Mudidir + "\ \" +File.getname ();                        Copydir (YuanJia, Mudijia); }                }        }        //Copying Files         Public Static voidCopyFile (file yuanfile, file mudifile)throwsException {bufferedinputstream Buis=NewBufferedinputstream (NewFileInputStream (Yuanfile.getabsolutefile ())); Bufferedoutputstream Buos=NewBufferedoutputstream (NewFileOutputStream (Mudifile.getabsolutefile ())); byte[] buf =New byte[1024]; intLen;  while(len = Buis.read (BUF))! =-1) {buos.write (buf,0, Len);                Buos.flush ();                } buis.close ();        Buos.close (); }}

Copy the C-drive folder to the D drive. Black Horse Programmer

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.