Tag:java file copy
Package Com.yqq.touristmanager.utils;import Java.io.file;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;public class FileUtils { Public FileUtils () {//TODO auto-generated Constructor stub}/** * @warning The name of the file must is end with. xls * @param Res The resource file * @param des the destination * @return * @throws filenotfoundexception */public Static Boolean to Copy (String res,string des) {Boolean flag=false; Boolean bool1 = Res.endswith (". xxx"); Boolean bool2 = Des.endswith (". Xxxb"); if (!bool1 &&!bool2) {return false;} Input source files File File = new file (res); FileInputStream fr=null;//Copy destination file Desfile = new file (DES); FileOutputStream Bw=null;try {fr = new FileInputStream (file), bw = new FileOutputStream (desfile);//bufferbyte[] B = new Byt E[512];while (Fr.read (b)!=-1) {bw.write (b);} Bw.flush (); flag=true;} catch (FileNotFoundException e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch (IoexcePtion e) {//TODO auto-generated catch Blocke.printstacktrace ();} Finally{if (fr! = null) try {fr.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} if (BW = null) {try {bw.close ()} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}} return flag;}}
Copy the. xxx format file to the specified path.
Java Copy File Tool class