Java Learning -012-File Delete instance and source code

Source: Internet
Author: User

The source code of this article is mainly for the application of Java to create files. If there is any deficiency, please ask the great God to correct me, I appreciate it!

The file deletion source code is as follows:

1     /**2 * @function file operation: Delete file. If the file exists and is not occupied, the file is deleted, and if the file exists and is occupied, the file occupancy information is recorded, and if the file does not exist, the corresponding log information3      * 4      * @authorAARON.FFP5      * @versionv1.0.0:autouiselenium main.java.aaron.java.tools Fileutils.java deletefile, 2015-2-2 21:03:41 Exp $6      * 7      * @paramFileName: File full path8      * 9      * @returnBoolean Delete successfully returns TRUETen      */ One      Public BooleanDeleteFile (String filename) { A         BooleanFlag =false; -          -         Try { theFile f =NewFile (filename); -              -             if(F.exists () &&F.renameto (f)) { - F.delete (); +                  ThisThe. Message = "{" + filename + "} file was successfully deleted. "; -                  This. Logger.info ( This. message); +                  AFlag =true; at}Else if(F.exists () &&!F.renameto (f)) { -                  This. Message = "{" + filename + "} file is in use and cannot be deleted! "; -                  This. Logger.warn ( This. message); -}Else{ -                  ThisThe. Message = "{" + filename + "} file does not exist. "; -                  This. Logger.warn ( This. message); in             } -}Catch(Exception e) { to              This. Message =e.getmessage (); +              This. Logger.error ( This. message); -         } the          *         returnFlag; $}
file Delete Source code

The test file deletion source code is as follows:

1     /**2 * Test: Delete file-fileutils.deletefile (String)3      * 4      * @authorAARON.FFP5      * @versionv1.0.0:autouiselenium test.java.aaron.java.tools Fileutilstest.java DeleteFile, March 9, 2015 PM 11:53:38 Exp $6      */7 @Test8      Public voidDeleteFile () {9          This. Message = "\n\n\n Test: Delete file-fileutils.deletefile (String)";Ten          This. Logger.debug ( This. message); One          AFu =NewFileUtils (); -          -          This. FileName = "I:\\cnblogs\\sourcecode\\autouiselenium\\test-output\\file\\txtfilewrite.txt"; the          -          This. message = "File deletion failed." The file path is: "+ This. FileName; -          -Assert.asserttrue ( This. Fu.deletefile ( This. FileName), This. message); +}
Test: File Delete Test source code

At this point, Java learning -012-file deletion instance and the source code successfully completed, I hope this article can give beginners Java you a reference.

Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^

Java Learning -012-File Delete instance and source code

Related Article

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.