java导出文本文件流

ExportController.java

//ids是导出的参数,可以根据实际情况修改
public void export(@RequestBody List<Integer> ids,
                                  HttpServletResponse response) {
        exportService.export(ids,response);
    }

ExportService.java

public void export(List<Integer> ids, HttpServletResponse response) {
response.setContentType("application/octet-stream");
try {
       response.setHeader("Content-Disposition", "attachment; filename="
                + URLEncoder.encode("export" + ".sql", "UTF-8"));
        OutputStream out = response.getOutputStream();
        out.write("数据!".getBytes());//这里可以写上自己的文件内容数据
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

你可能感兴趣的:(java,python,windows)