1 ImportJava.io.BufferedInputStream;2 ImportJava.io.BufferedOutputStream;3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 ImportJava.io.FileOutputStream;6 ImportJava.io.InputStream;7 ImportJava.io.OutputStream;8 9 /**Ten * Classes for file backup One * A * for various types of file backup, under the path of the original file, create a backup file, named the original file name. bak - */ - Public classFileUtils { the Public StaticString backup_suffix = ". Bak"; - - /** - * functions to implement file copying + * - * Read and write files using binary stream format + */ A Public Static voidFileCopy (file srcfile, file destfile)throwsexception{ atInputStream src =NewBufferedinputstream (NewFileInputStream (srcfile)); -OutputStream dest =NewBufferedoutputstream (NewFileOutputStream (DestFile)); - - byte[] trans =New byte[1024]; - - intCount =-1; in - while((count = Src.read (trans))! =-1){ toDest.write (trans, 0, count); + } - the Dest.flush (); * src.close (); $ dest.close ();Panax Notoginseng } - the /** + * Backup files, create backup files in the original file directory, name the original filename. bak A * @paramtemplatefile functions that need to be backed up the * @returntrue Success, False failed + */ - Public Static Booleanbackuptemplatefile (String templatefile) { $ BooleanFlag =true; $ -File Srcfile =NewFile (templatefile); - if(!srcfile.exists ()) { theSystem.out.println ("Template file does not exist"); - return false;Wuyi } the - //Create a backup file WuFile BackUpFile =NewFile (templatefile+backup_suffix); - Try { About if(Backupfile.createnewfile ()) { $ //Create backup file successfully, make file copy - fileCopy (Srcfile, backUpFile); - } -}Catch(Exception e) { AFlag =false; +SYSTEM.OUT.PRINTLN ("Backup file Failed"); the } - $ returnFlag; the } the}