title: How to give MultiPartfile to Reader in Java?
body: <p>I am passing MultiPartFile as a parameter to my function and read with CSVFormat, but it gives me null pointer exception here is my code.</p>
  
  <p>I want to read from file and assign that values to my objects.
  My CSV file like this:</p>
  
  <p>Sender account,Receiver Account,Amount,Date</p>
  
  <p>123,654321,100,19-07-2018 12:13:00</p>
  
  <pre><code>public List&lt;BankAccount&gt; readCsv(MultipartFile file) throws IOException {
          List&lt;BankAccount&gt; bankAccountList = new ArrayList&lt;BankAccount&gt;();
  
          DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
  
  
  
          Reader in = new InputStreamReader(BankAccount.class.getClassLoader()
                  .getResourceAsStream(file.getOriginalFilename()));
  
          Iterable&lt;CSVRecord&gt; parser = CSVFormat.EXCEL.withHeader("Sender account","Receiver Account","Amount","Date").parse(in);
  
  
              for (CSVRecord csvRecord : parser) {
              BankAccount bankAccount = new BankAccount();
              String senderAccount = csvRecord.get("Sender account");
              String receiverAccount = csvRecord.get("Receiver account");
              float amount = Float.parseFloat(csvRecord.get("Amount"));
              ZonedDateTime date = LocalDateTime.parse(csvRecord.get("Date"), dtf)
                      .atZone(ZoneId.of("Asia/Istanbul"));
              bankAccount.setFromId(senderAccount);
              bankAccount.setToId(receiverAccount);
              bankAccount.setDate(date);
              bankAccount.setBalance(amount);
              bankAccountList.add(bankAccount);
          }
  
          return bankAccountList;
      }
  </code></pre>