Notepad is one of the places where you notice that \n is not platform-independent. It requires the proper DOS/Windows line separator of "\r\n". WordPad obviously can convert \n to a line separator, as can quite a lot of other applications. You are better using a println() method, or
You need "finally" round the Writer, otherwise an Exception after it is created will prevent it from closing, and will keep the file in use and unavailable for other applications.
The customary way to do it with a BufferedWriter would look like this (old-fashioned style used)Of course, since Java 5 you would use a Formatter and the %n tag. The %n tag gives you the exact line separator for your operating system. This is much easier to use; you can test whether there are any problems at the end by saying
wroteOK = format.ioException() == null; That means you are returning "false" if an exception occurred, otherwise assume all is well and return true. You might still have to catch a FileNotFoundException when you create a File to pass to the Formatter, however. The only problem with Formatters is that you can't append (at least I have never found how to append with a Formatter).