How to save file in memory and read file output stream?
<p>When I save file I use: </p>

<pre><code>File file = new File(filename);
</code></pre>

<p><strong>But, since I no longer have privileges to write to folders,</strong> I would like rather to save it to memory and then read file to FileOutputStream.</p>

<p>I have read I can save file to memory with this approach:</p>

<pre><code>new ByteArrayOutputStream(); 
</code></pre>

<p>How would whole code look like? I can't figure it out how to write it properly after upload is done. </p>

<p>Edit: I'm using Vaadins upload plugin:</p>

<pre><code>public File file;

    public OutputStream receiveUpload(String filename,
                                      String mimeType) {

        // Create upload stream
        FileOutputStream fos = null; // Stream to write to
        file = null;

        if(StringUtils.containsIgnoreCase(filename, ".csv")){
            try {

                file = new File(filename);
                fos = new FileOutputStream(file);
            } catch (final java.io.FileNotFoundException e) {

                new Notification("Error", e.getMessage(), Notification.Type.WARNING_MESSAGE)
                    .show(Page.getCurrent());
                return null;
            }
        } else {

            new Notification("Document is not .csv file", Notification.Type.WARNING_MESSAGE)
                .show(Page.getCurrent());
            return null;
        }
        return fos; // Return the output stream to write to
    }
</code></pre>