title: Is there a way to provide file download without reading the file from path in Java?
body: <p>In my program I have a getRequest (JavaSpark) that offers me an Excel file created in Java for download.</p>
  <p>To do this, I create the Excel file, save it in a folder and then read the file via the path.</p>
  <p>Works.</p>
  <p>Code - ExcelCreation:</p>
  <pre><code>public void createPlanWorkbook() throws Exception {
      ...
      ... 
      do something with workbook...
  
      workBook.write(&quot;C:\\Users\\Develope\\Desktop\\Excel.xlsm&quot;);
  }
  </code></pre>
  <p>Code - request:</p>
  <pre><code>get(&quot;/excelfile&quot;, ((request, response) -&gt; {
      response.header(&quot;Content-disposition&quot;, &quot;attachment; filename=Excel.xlsm;&quot;);
  
      File file = new File(&quot;C:\\Users\\Develope\\Desktop\\Excel.xlsm&quot;);
      OutputStream outputStream = response.raw().getOutputStream();
      outputStream.write(Files.readAllBytes(file.toPath()));
      outputStream.flush();
      return response;
  }));
  </code></pre>
  <p>I wonder if there is another way to implement this. Is the step of saving and then reading the file necessary? Or is there a way to put the file directly from Javaobject into the request.</p>
  <p>For example:</p>
  <pre><code>outputStream.write(ExcelCreaterObject().getWorkbook());
  </code></pre>