copy a single file

具体的不说啦,只是一个函数,很 easy的,调用方法如下:

try {
     copySingleFile(list.get(i).getAttname(), filename,
       pathBuilder.toString(), attkey);
    } catch (FileNotFoundException e) {
     e.printStackTrace();
    } catch (IOException e) {
     e.printStackTrace();
    }

 

函数如下:

 

/**
  * 文件复制业务逻辑实现
  * @param srcFileName 源文件名
  * @param destFileName 目标文件名
  * @param rootPath 文件所操作路径
  * @param attkey 文复制文件的数据KEY
  *           
  * @return
  * @throws BLException
  * @throws IOException
  * @throws FileNotFoundException
  */
 public void copySingleFile(String srcFileName, String destFileName,String rootPath,String attkey) throws FileNotFoundException,
 IOException, BLException {

 // 目标文件
  File destFile = new File(rootPath + attkey + "_" + destFileName);
  // 源文件
  File srcFile = new File(rootPath + srcFileName);
  /** 源文件文件流取得 */
  InputStream is = new FileInputStream(srcFile);

  /** 输入文件流缓存取得 */
  BufferedInputStream inBuffer = new BufferedInputStream(is);

  /** 目标文件文件保存流取得 */
  FileOutputStream out = new FileOutputStream(destFile);

  /** 目标文件文件保存流缓存取得 */
  BufferedOutputStream outBuffer = new BufferedOutputStream(out);

  /** 复制文件保存 */
  int contents = 0;

  while ((contents = inBuffer.read()) != -1) {
   outBuffer.write(contents);
  }

  outBuffer.flush();

  // 文件流关闭
  inBuffer.close();
  outBuffer.close();
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值