Fileutils file Tool

Source: Internet
Author: User
Import Java. io. file; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. io. outputstreamwriter; /*** file operation tool class ** @ author administrator **/public class fileutils {/*** get file extension *** @ Param filename * @ return */public static string getextend (string filename) {return getextend (filename, "");}/*** Get file extension ** @ Param filename * @ return */public static string getextend (string filename, string defext) {If (filename! = NULL) & (filename. length ()> 0) {int I = filename. lastindexof ('. '); If (I> 0) & (I <(filename. length ()-1) {return (filename. substring (I + 1 )). tolowercase () ;}} return defext. tolowercase ();}/*** get file name [without suffix name] ** @ Param * @ return string */public static string getfileprefix (string filename) {int splitindex = filename. lastindexof (". "); Return filename. substring (0, splitindex ). replaceall ("\ s *", "");}/*** File copy * method Abstract: Here is a sentence describing the purpose of the Method * @ Param * @ return void */public static void copyfile (string inputfile, string outputfile) throws filenotfoundexception {file sfile = new file (inputfile); file tfile = new file (outputfile); fileinputstream FD = new fileinputstream (sfile ); fileoutputstream Fos = new fileoutputstream (tfile); inputstreamreader in = NULL; outputstreamwriter out = NULL; int temp = 0; char [] B UF = new char [2048]; try {In = new inputstreamreader (Adams, "UTF-8"); out = new outputstreamwriter (FOS, "UTF-8 "); while (temp = in. read (BUF ))! =-1) {out. write (BUF, 0, temp) ;}} catch (ioexception e) {e. printstacktrace ();} finally {try {In. close (); out. close ();} catch (ioexception e) {e. printstacktrace ();}}} /*** determine whether the file is an image <br> * <br> ** @ Param filename * file name <br> * determine the specific file type <br> * @ return result <br> * @ throws exception */public static Boolean ispicture (string filename) {// If (oconvertutils. isempty (filename) {// return false if the returned result is invalid;} // obtain the file suffix // string tmpname = getextend (filename); string tmpname = filename; // declare the image suffix array string imgearray [] [] = {"BMP", "0" },{ "Dib", "1" },{ "GIF ", "2" },{ "jfif", "3" },{ "jpe", "4" },{ "Jpeg", "5" },{ "jpg ", "6" },{ "PNG", "7" },{ "TIF", "8" },{ "tiff", "9" },{ "ICO ", "10" }}; // retrieve the name array for (INT I = 0; I  * <br> ** @ Param filename * file name <br> * determine the specific file type <br> * @ return result <br> * @ throws exception */public static Boolean isdwg (string filename) {// If (oconvertutils. isempty (filename) {// return false if it is not legal;} // get the file suffix string tmpname = getextend (filename); // declare the image suffix array if (tmpname. equals ("DWG") {return true;} return false ;}}

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.