Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you ever close the writer?</p> <p>In general, whenever you create an I/O resource (such as a reader/writer/database connection/etc), you should use a <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html" rel="nofollow">finally block</a> to ensure it's closed, something like this:</p> <pre><code>Writer writer = new BufferedWriter(...); try { // do something with the writer; may be many lines of code } finally { writer.close(); } </code></pre> <p>(Note: Java 7 has more concise syntax for this pattern, <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" rel="nofollow">the try-with-resources block</a>.)</p> <p>This is important for resource management (for example, if you don't close connections/files then eventually your process will run out of file handles and will not be able to open any more).</p> <p>However, there's a more relevant issue too. Many writers are buffered, to avoid the performance hit of writing one character at a time to the underlying operating system. When you call <code>write</code> on them, they store that data in a buffer, and only actually write it to the file periodically (when it's "big enough" to be worth it) - this is called <em>flushing</em>.</p> <p>If the writer is simply discarded before it has flushed the data, the file won't be updated.</p> <p>You can call <code>flush()</code> manually, but it's rarely needed - calling <code>close()</code> on the writer will not only release all its resources, but will flush the buffers as well. So with the <code>try / finally</code> pattern laid out above, it's <em>guaranteed</em> that whatever you write within the <code>try</code> block will be written to the file when your process terminates. With your current code, there are no guarantees and it depends on the implementation of the writer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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