Saturday, April 20, 2013

Write a String to file

This is the reverse operation of Reading whole file into a String.

There are more than one ways of doing this. We may use FileWriter or FileOutputStream to achieve the purpose. The following sample wraps a FileWriter with a PrintWriter to print a String to the file.

Since this is only a demonstration and I don't want to do anything destructive, the program will NOT overwrite any existing file. You may turn on the overwrite mode following the comment below.

No comments:

Post a Comment