Java Learning -008-Judging file type instances

Source: Internet
Author: User

The source of this article mainly for the application of Java how to determine the file type of source code and test source code. If there is any deficiency, please ask the great God to correct me, I appreciate it! Source code test pass date is: 2015-2-2 23:02:00, please be aware.

Java Judging file Type the source code is as follows:

1     /**2 * @function determine file type3      * 4      * @authorAARON.FFP5      * @versionv1.0.0:autouiselenium main.java.aaron.java.tools Fileutils.java assertfiletype, 2014-11-25 17:49:36 Exp $6      * 7      * @paramFileName : File name8      * @paramfiletype: File type: {EXCEL, CSV, XML, TXT, LOG, DBF, INI, WORD, POWERPOINT, PROPERTIES}9      * Ten      * @returnBoolean One      */ A      Public Booleanassertfiletype (string filename, string filetype) { -         BooleanSuccess =false; -          the         /*file extension: Get file name extensions and convert to lowercase*/ -String fileextension = filename.substring (Filename.lastindexof (".") + 1). toLowerCase (); -          -         if(! This. Constantslist. Filetype.get (FILETYPE). StartsWith (FileExtension)) { +              This. message = "argument illegal: Second parameter {file type} illegal, file type {" + FileExtension + "} Not in File type list [" + This. constantslist. Filetype.tostring () + "], not supported!"; -              This. Logger.error ( This. message); +}Else { ASuccess =true; at         } -          -         returnsuccess; -}
determine file type source code

The test source is as follows:

1     /**2 * Test: Verify file Type3      * 4      * @authorAARON.FFP5      * @versionv1.0.0:autouiselenium test.java.aaron.java.tools Fileutilstest.java assertfiletype, 2015-2-2 23:02:00 EXP $ 6      */7 @Test8      Public voidAssertfiletype () {9Fu =NewFileUtils ();TenString filename_ = "I:\\cnblogs\\sourcecode\\autouiselenium\\test-output\\file\\txtfilewrite.txt"; OneString expected = "TXT"; A          -Assert.asserttrue (Fu.assertfiletype (filename_, expected), "file type checksum failed"); -}
test: Verify that the file type is judged correctly

At this point, Java Learning -008-to determine the file type instance successfully completed, I hope this article can give beginners Java 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 -008-Judging file type instances

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.