Java doesn't want me to close outputStream before using an inputStream?
<p>I've got (an admittedly strange) try/catch block that checks if a <code>File</code> exists. If it doesn't, then I create it and write a <code>File</code> to it. Then I read the <code>File</code>. </p>

<p>I have an <code>ArrayList</code> that is being initialized by reading an object from an <code>ObjectInputStream</code>. In the original writing of the file using a <code>FileOutputStream</code> and an <code>ObjectOutputStream</code>, if I call <code>close()</code> on them, then my <code>ArrayList</code> remains <code>null</code>. If I simply remove the calls to <code>close()</code>, everything goes as planned.</p>

<p>This seems backwards to me. I would think that the file system is somehow "locked" if I've got some type of <code>stream</code> open to it. That's why I thought to close the <code>outputStreams</code> before using an <code>inputStream</code>. But no, Java won't let this work unless I keep the <code>outputStreams</code> open. </p>

<p>Here's my code, including the commented out calls to <code>close()</code> which allows this to work properly:</p>

<pre><code>try {
                File file = context.getFileStreamPath("file");    
            } catch (Throwable e) {
                e.printStackTrace();

                try {
                FileOutputStream fileOutputStream = context.openFileOutput("file", Context.MODE_PRIVATE);
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);

                reminders = new ArrayList&lt;Reminder&gt;();
                objectOutputStream.writeObject(reminders);
//                fileOutputStream.close();
//                objectOutputStream.close();
                } catch (Throwable t) {
                     t.printStackTrace();
                }
            }

         try {
            FileInputStream fileInputStream = context.openFileInput("file");
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            if (objectInputStream != null) {
                reminders = (ArrayList&lt;Reminder&gt;) objectInputStream.readObject();
            }
        }  catch (Throwable t) {
                     t.printStackTrace();
        }
</code></pre>
