The copy and cut functions of files are simple, and the copy and cut functions are implemented.

Source: Internet
Author: User

The copy and cut functions of files are simple, and the copy and cut functions are implemented.

The copy and cut methods of personal files are a rare little ape. What are the disadvantages?
/***** @ Param tarPath copy the file to that path * @ param sourcePath copy file path * @ throws IOException * // public void copyFile (String tarPath, string sourcePath) throws IOException {File tarFile = new File (tarPath); if (! TarFile. exists () {tarFile. createNewFile ();} File sourceFile = new File (sourcePath); try {// create a File input stream FileInputStream FS = new FileInputStream (sourceFile ); // input stream buffer BufferedInputStream bis = new BufferedInputStream (FCM); byte [] buffer = new byte [bis. available ()]; bis. read (buffer); bis. close (); FCM. close (); // create a file output stream FileOutputStream fos = new FileOutputStream (tarFile); BufferedOutputStream bos = new BufferedOutputStream (fos); // write data to the output stream bos. write (buffer); // refresh bos here. flush (); bos. close ();} catch (FileNotFoundException e) {// TODO Auto-generated catch block e. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch block e. printStackTrace () ;}// delete a file (you can also cut the file after copying it) /***** @ param sourcePath path of the File to be deleted */public void deleteFile (String sourcePath) {File tarFile = new File (sourcePath); if (tarFile. isFile () tarFile. delete ();}

 

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.