public static void writeStringToFile(final File file, final String data, final Charset encoding, final boolean
            append) throws IOException {
        OutputStream out = null;
        try {
            out = openOutputStream(file, append);
            IOUtils.write(data, out, encoding);
            out.close(); // don't swallow close Exception if copy completes normally
        } finally {
            CloseableUtils.closeQuietly(out);
        }
    }
Writes a String to a file creating the file if it does not exist.

@param file     the file to write
@param data     the content to write to the file
@param encoding the encoding to use, {@code null} means platform default
@param append   if {@code true}, then the String will be added to the
                end of the file rather than overwriting
@throws IOException in case of an I/O error
replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/utils/FileUtils.java