You're not closing the writer, which means there's data still in the buffer. You should close it (and all the other streams etc) in finally
blocks, or use a try-with-resources statement if you're using Java 7.
Also note that the way you're currently "handling" exceptions is to pretty much ignore them and proceed - which means that after one thing's failed, you'll almost certainly get another failure. Rip out those try/catch blocks, and just let the exception propagate up. (Declare that your main
method can throw IOException
.)