代码之家  ›  专栏  ›  技术社区  ›  Shahid Ghafoor

将CSV文件写入MultipartFile

  •  1
  • Shahid Ghafoor  · 技术社区  · 7 年前

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.5</version>
    </dependency>
    

    将CSV写入 ByteArrayOutputStream

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final CSVFormat format = CSVFormat.DEFAULT;
    final CSVPrinter csvPrinter;
    try {
      csvPrinter = new CSVPrinter(new PrintWriter(out), format);
      csvPrinter.printRecord("12,ABC,XYZ");
      csvPrinter.printRecord("13,LMN,PQR");
      csvPrinter.flush();
      csvPrinter.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    

    ResponseEntity<ObjectResponseBo> uploadFile(@RequestHeader("Authorization") String var1, @RequestParam("file") MultipartFile var2);
    

    如何转换 ByteArrayOutputStream公司 MultipartFile 对象,这样我就可以在我的外呼中使用csv文件了?

    0 回复  |  直到 7 年前