复制a文件夹的文件到b文件夹

    public Map<String, Object> testIn() throws Exception {
        Map<String,Object> res = new HashMap<>();;
        FileInputStream in = null;
        FileOutputStream out = null;

        String oldPath = "E:\\123";
        File fuFile = new File(oldPath);
        String[] list = fuFile.list();// 文件夹
        for (int i = 0; i < list.length; i++) {
            String fileName = list[i];
            String newPath = "E:\\newPaht\\"+fileName;
            String count = goodsService.getCountBySupplierGoodsId(fileName);// 和数据库中已有数据进行匹配(可无)
            if (!isEmpty(count) && Integer.parseInt(count) > 0){
                if (!(new File(newPath)).exists()) {
                    (new File(newPath)).mkdir();
                }
                String wjPath = oldPath+"\\"+fileName;// 图片所在文件夹
                File wjFile = new File(wjPath);
                String[] wjName = wjFile.list();// 文件夹
                for (int wji = 0; wji < wjName.length; wji++) {
                    String wj = wjName[wji];

                    File file = new File(newPath+"\\"+wj);
                    in = new FileInputStream(oldPath+"\\"+fileName+"\\"+wj);
                    out = new FileOutputStream(file);

                    byte[] buffer=new byte[20971];
                    int readByte = 0;
                    while((readByte = in.read(buffer)) != -1){
                        out.write(buffer, 0, readByte);
                    }
                }

            }
        }

        in.close();
        out.close();
        return res;
    }

 

注:io是针对文件的,如果复制问加价的话   会抛出  路径:(拒绝访问)  错误

      路径需精确到文件名称

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值