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