COPY FILE

来源:互联网 发布:java web spring mvc 编辑:程序博客网 时间:2024/05/24 07:24

private String copyFile(File src, File dst) {
  if(!dst.getParentFile().exists()){
   dst.getParentFile().mkdir();
  }
  dst = getFileWithSuffixTimeStamp(dst); //METHOD call : append time stamp in file
  try{
   InputStream inst = new FileInputStream(src);
   OutputStream outst = new FileOutputStream(dst);
      byte[] buf = new byte[1024];
      int len;
      while ((len = inst.read(buf)) > 0) {
       outst.write(buf, 0, len);
      }
      inst.close();
      outst.close();
  }catch(IOException ie){
    throw ie;
  }

  return dst.getAbsolutePath();
 }