欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java复制文件工具类,,import java.

来源: javaer 分享于  点击 36420 次 点评:31

Java复制文件工具类,,import java.


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);              //buffer              byte[] b = new byte[512];              while(fr.read(b)!=-1){                  bw.write(b);              }              bw.flush();              flag=true;          } catch (FileNotFoundException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }catch (IOException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }finally{              if(fr != null)                  try {                      fr.close();                  } catch (IOException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }              if(bw != null){                  try {                      bw.close();                  } catch (IOException e) {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }              }          }          return flag;      }  }  

把.xxx格式的文件复制到指定路径。

相关栏目:

用户点评