记录|Java输出文件流

需求是,输出一个文件给另一个团队,然后他们来定期拉取数据

public ResponseEntity topicRank() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); String filename = "topic_rank"; LinkedMultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("Content-Type", "application/text"); headers.add("Content-Disposition", "attachment; filename=" + new String(filename.getBytes("GBK"), "iso8859-1")+".xlsx"); //获取对应的数据信息,转换成string String topicRank = hotelBangdanService.getHotelBangdanData(0L, "", 1); baos.write(topicRank.getBytes(), 0, topicRank.getBytes().length); return new ResponseEntity(baos.toByteArray(), headers, HttpStatus.OK); } catch (Exception ex) { return null; } }


    推荐阅读