Moving files using Java

Source: Internet
Author: User

When using Java to move files, the main use of the file class in IO is to use the Renameto method in the file class to implement the move of the file, as follows:

Private Boolean RemoveFile (String filename,string destinationfloderurl) {File File = new file (fileName);
        File Destfloder = new file (Destinationfloderurl); Check that the target path is legitimate if (destfloder.exists ()) {if (Destfloder.isfile ()) {T His.logger.error (The target path is a file, check the target path.)
                ");
            return false; }}else {if (!destfloder.mkdirs ()) {this.logger.error ("Destination folder does not exist, create Build failed.
                ");
            return false; Check if the source file is legitimate if (File.isfile () &&file.exists ()) {String destination
            File = destinationfloderurl+ "/" +file.getname (); if (!file.renameto new file (Destinationfile)) {this.logger.error ("Move file) failed."
                ");
            return false; }}else {This.logger.error ("The file path to be backed up is incorrect and the move failed."
            ");
       return false; This.logger.info ("Moved files successfully" +file.getname () + "to" +destinationfloderurl);
    return true;
 }

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.