read data from MultipartFile which has csv uploaded from browser

前端 未结 3 1856
无人及你
无人及你 2020-12-30 02:46

May be I am doing it worng by using MultipartFile upload feature.

I have to read data from csv file which will be chosen by the client through the browser. I used Mu

3条回答
  •  甜味超标
    2020-12-30 03:10

    I figured out a workaround. I converted the file to bytes and then converted the bytes to String. From String I applied string.split() to get what I wanted out of the file.

        @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public String uploadFileHandler(@RequestParam("file") MultipartFile file) {
        if (!file.isEmpty()) {
            try {
                byte[] bytes = file.getBytes();
                String completeData = new String(bytes);
                String[] rows = completeData.split("#");
                String[] columns = rows[0].split(",");
    

提交回复
热议问题