admin管理员组

文章数量:1530842

String fileName = "短信模版.txt";
OutputStream os = null;
try {
    response.reset();
    response.setContentType("application/octet-stream; charset=utf-8");
    response.setHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes(),"ISO8859-1"));
    byte[] bytes = sb.toString().getBytes("GBK");
    os = response.getOutputStream();
    // 将字节流传入到响应流里,响应到浏览器
    os.write(bytes);
    os.close();
} catch (Exception ex) {
    logger.error("导出失败:", ex);
    throw new RuntimeException("导出失败");
}finally {
    try {
        if (null != os) {
            os.close();
        }
    } catch (IOException ioEx) {
        logger.error("导出失败:", ioEx);
    }
}

 

本文标签: 字符串进行下载后台浏览器文件