Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your <code>DataOutputStream</code> inherits it's <code>close()</code>-method from <code>FilterOutputStream</code> whom's <a href="http://docs.oracle.com/javase/6/docs/api/java/io/FilterOutputStream.html#close%28%29" rel="nofollow">documentation</a> states that:</p> <blockquote> <p>Closes this output stream and <strong>releases any system resources associated with the stream.</strong></p> <p>The close method of FilterOutputStream calls its flush method, and <strong>then calls the close method of its underlying output stream.</strong></p> </blockquote> <p>The same should be true for all <code>Writer</code>-implementations (although it's not stated in the docs).</p> <hr> <p>To avoid running into memory problems when working with Streams in Java, use this pattern:</p> <pre><code>// Just declare the reader/streams, don't open or initialize them! BufferedReader in = null; try { // Now, initialize them: in = new BufferedReader(new InputStreamReader(in)); // // ... Do your work } finally { // Close the Streams here! if (in != null){ try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>This looks less messy with Java7 because it introduces the <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html" rel="nofollow"><code>AutoCloseable</code>-interface</a>, which is implemented by all Stream/Writer/Reader classes. See the <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" rel="nofollow">tutorial</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload