creating an excel file in memory using java and pass as bytes for downloading
<p>I have created a excel file using <strong>jxl</strong> library. The code is working fine but the only problem is that each time for building an excel file from the dynamic values coming from a service, the excel content is overwriting onto a <strong>test.xls</strong> like as shown below. Is there any way to build an excel in memory and pass the byte for downloading it instead of creating an external file ("<strong>test.xls</strong>")</p>

<pre><code>File file = new File("test.xls");
WritableWorkbook workbook = Workbook.createWorkbook(file);
:
:
:
:

InputStream in = new FileInputStream(file);

if (in == null) {
    out.close();
}
else 
{
    byte[] buffer = new byte[4096];
    int len;

    while ((len = in.read(buffer)) != -1) {
        out.write(buffer, 0, len);
    }

    out.flush();
    in.close();
    out.close();
}
</code></pre>

<p>Can anyone please help me on this</p>