This week's book giveaway is in the OCAJP forum. We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line! See this thread for details.
Presizing the StringWriter is optional, but improves performance. Here I assumed that the file encoding was one byte per character. If that's not the case you may wish to presize differently - e.g. for UTF-16 use