Java复制文件工具类

来源:互联网 发布:mac虚拟机安装win7 编辑:程序博客网 时间:2024/05/18 00:43
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 file must be end with .xls * @param res The resource file * @param des The destination * @return  * @throws FileNotFoundException  */public static boolean toCopy(String res,String des){boolean flag=false;Boolean bool1 = res.endsWith(".xxx");Boolean bool2 = des.endsWith(".xxxb");if(!bool1 && !bool2){return false;}//输入源文件File file = new File(res) ;FileInputStream fr=null;//复制目标文件File desFile = new File(des);FileOutputStream bw=null;try {fr = new FileInputStream(file);bw = new FileOutputStream(desFile);//bufferbyte[] b = new byte[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;}}

把.xxx格式的文件复制到指定路径。
0 0
原创粉丝点击