Java Copy File Tool class

Source: Internet
Author: User
Tags file copy

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

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.