title: How to validate csv read data - Spring boot java
body: <p>MY code is take csv File and read line by line and store to database .
  How to validate each line data is correct or not.
   if correct all read data then only store database else not store and return "csv file in correct data please check".</p>
  
  <p>county name validation should be string/ only text,
  country code validation  should be only number and max 4 digte</p>
  
  <p>Here is my code is working fine with out any validate</p>
  
  <pre><code>@PostMapping(value = {"/upload-csv"})
  
  public ResponseEntity&lt;?&gt; CreateCountrytBulk(@RequestParam("file") MultipartFile inputFile, @RequestParam("type") Integer type) {
          BufferedReader crunchifyBuffer = null;
              String workingDir = System.getProperty("user.dir") +"/csv/";
              if (!inputFile.isEmpty()) try {
                  byte[] bytes = inputFile.getBytes();
                  Path path = Paths.get(workingDir + inputFile.getOriginalFilename());
                  Files.write(path, bytes);
                  countryCodeMapRepository.deleteAll();
                  CSVReader reader = null;
  
                  try {
                      reader = new CSVReader(new   FileReader(workingDir+ inputFile.getOriginalFilename()));
                      String[] line;
                      while ((line = reader.readNext()) != null) {
                          String y = line[0];
                          String country_name=y.trim();
                          String x = line[1];
                          Integer country_id = Integer.valueOf(x);
                          CountryCodeMapEntity countryCodeMapEntity = new CountryCodeMapEntity();
                          if(!(country_name ==null)&amp;&amp;!(country_id ==null)) {
                              countryCodeMapEntity.setCountry_name(country_name);
                              countryCodeMapEntity.setCountry_id(country_id);
                              countryCodeMapEntity.setStatus(1);
                              countryCodeMapEntity.setCreatedBy(1);
                              countryCodeMapEntity.setCreatedOn(LocalDateTime.now());
  
                              countryCodeMapRepository.save(countryCodeMapEntity);
                          }else{
                              return ResponseEntity.ok(new ApiResponse(false, "County List some value missing", ""));
  
                          }
                      }
                  }  catch (IOException e) {
                      e.printStackTrace();
                  }
                  return ResponseEntity.ok(new ApiResponse(true, "County List created successfully", ""));
              } catch (Exception e) {
                  return ResponseEntity.ok(new ApiResponse(true, "County List created successfully", ""));
              }
              else {
                  return ResponseEntity.ok(new ApiResponse(true, "County List created successfully", ""));
              }
          }
  </code></pre>