Java Text File Save serialize(final File folder, final String content, final String fileName)

Here you can find the source of serialize(final File folder, final String content, final String fileName)

Description

Serialize a content into a targeted file, checking that the parent directory exists.

License

Apache License

Parameter

Parameter Description
folder File
content String
fileName String

Declaration

public static void serialize(final File folder, final String content, final String fileName)
        throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**//from  w w  w  .  j  a  v a  2 s  .  c o  m
     * Serialize a content into a targeted file, checking that the parent directory exists.
     *
     * @param folder File
     * @param content String
     * @param fileName String
     */
    public static void serialize(final File folder, final String content, final String fileName)
            throws IOException {
        if (!folder.exists()) {
            folder.mkdirs();
        }

        final File output = new File(folder, fileName);
        FileWriter writer = null;

        try {
            writer = new FileWriter(output);
            writer.write(content);
            writer.flush();
        } catch (Exception e) {
            throw new IOException("Failed to serialize the notification in folder " + folder.getPath(), e);
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }
}

Related

  1. setText(File file, String text)
  2. writeFile(ArrayList lines, String dest_path)
  3. writeFile(Collection emailTree, String destFile)
  4. writeFile(File destinationFile, String contents, String encoding)