数据库中读出的数据组装TXT进行下载

txt格式下载

public Object downloadPackage( Long id,HttpServletResponse response) throws Exception {
    if (null != id && id > 0) {
        CpNumberPackage numPack = this.cpNumberPackageService.findOne(id);
        if (numPack != null && numPack.getCpId().equals(getCurrentCpId())) {
            String txtContent = numPack.getNumbers();
            String pathName = numPack.getName();
            byte[] result = txtContent.getBytes();
            OutputStream outputStream = response.getOutputStream();
            try {
                response.reset();
                response.setHeader("Content-disposition", "attachment;filename=" +
                        URLEncoder.encode(pathName, "UTF-8") + ".txt");
                response.setContentType("application/force-download");
                outputStream.write(result);
                outputStream.flush();
            }
            finally {
                if (outputStream != null) {
                    outputStream.close();
                }
            }

        }
    }
    return RestResult.failure();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值