title: Java Convert MultipartFile to File for large files
body: <p>I'm using the below method to convert MultipartFile to a File :</p>
  
  <pre><code>public File convert(MultipartFile file) throws IOException {
          File convFile = new File(file.getOriginalFilename());
          convFile.createNewFile();
          FileOutputStream fos = new FileOutputStream(convFile);
          fos.write(file.getBytes());
          fos.close();
          return convFile;
  }
  </code></pre>
  
  <p>Wich work's fine but for large files I got this exception :</p>
  
  <pre><code>java.lang.OutOfMemoryError: Java heap space
  </code></pre>
  
  <p>I added more heap but still having the error.</p>
  
  <p>So is there a programmatic way to fix this maybe splitting the multipart file to smaller chunks while converting, but I'm not sure how to code it.</p>
  
  <p>Any help or suggestion would be greatly appreciated.</p>