我有以下代码:
@RequestMapping(method = RequestMethod.POST, value = "/GEM-9639", produces = "text/plain", consumes="multipart/form-data")
public void convertCSVtoJO(HttpServletResponse response,
@FormDataParam("file") InputStream inputStream) {
try{
byte[] file = BinaryDataHelper.readAvailableToBuffer(inputStream);
FileOutputStream fos = new FileOutputStream("/tmp/CSVtmp.cvs");
fos.write(file);
fos.close();
//Create the CSVFormat object
CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(',');
//initialize the CSVParser object
CSVParser parser = new CSVParser(new FileReader("/tmp/CSVtmp.cvs"), format);
它会创建文件,但是会给它一个标题,它会丢弃我的解析器,无论如何都要从文件中删除这个页眉和页脚>
文件顶部:
------WebKitFormBoundaryCWCNJvEWAF8i1jgW
Content-Disposition: form-data; name="file"; filename="Cleaned-Inc-Town-County.csv"
Content-Type: text/csv
底
------WebKitFormBoundaryCWCNJvEWAF8i1jgW--
我通过我的休息客户端POSTMAN传递文件。