title: Read CSV File While Upload in Spring Boot
body: <p>I have code in <strong>spring boot</strong> for upload file. Already success upload and put file in the folder. I already got code from running with batch service. But I still confuse for read data CSV from upload data.</p>
  
  <p>I want modify. When I upload file "especially csv" the system will show data in CSV file. </p>
  
  <p>Could you help me, how can I get data from CSV while I upload ?</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>package com.mkyong.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.multipart.MultipartFile;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  
  import java.io.IOException;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  
  @Controller
  public class UploadController {
  
      //Save the uploaded file to this folder
      private static String UPLOADED_FOLDER = "D:\\spring\\video\\";
  
      @GetMapping("/")
      public String index() {
          return "upload";
      }
  
      @PostMapping("/upload") // //new annotation since 4.3
      public String singleFileUpload(@RequestParam("file") MultipartFile file,
                                     RedirectAttributes redirectAttributes) {
  
          if (file.isEmpty()) {
              redirectAttributes.addFlashAttribute("message", "Please select a file to upload");
              return "redirect:uploadStatus";
          }
  
          try {
  
              // Get the file and save it somewhere
              byte[] bytes = file.getBytes();
              Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
              Files.write(path, bytes);
              redirectAttributes.addFlashAttribute("message",
                      "You successfully uploaded '" + file.getOriginalFilename() + "'");
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          return "redirect:/uploadStatus";
      }
  
      @GetMapping("/uploadStatus")
      public String uploadStatus() {
          return "uploadStatus";
      }
  
  }
  </code></pre>
  
  <p><strong>MODEL</strong></p>
  
  <pre><code>package com.mkyong.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="article")
  public class User {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      @Column(name="title")
      private String title;
  
      @Column(name="category")
      private String category;
  
      public long getId() {
          return id;
      }
      public void setId(long id) {
          this.id = id;
      }
      public String getTitle() {
          return title;
      }
      public void setTitle(String title) {
          this.title = title;
      }
      public String getCategory() {
          return category;
      }
      public void setCategory(String category) {
          this.category = category;
      }
  
  
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Spring Boot file upload example&lt;/h1&gt;
  
  &lt;form method="POST" action="/upload" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="file" /&gt;&lt;br/&gt;&lt;br/&gt;
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I was searched in youtube and tutorial website but I can not found the method. </p>