Java Text File Save writeFile(final File outputFile, final String data, final String encoding)

Here you can find the source of writeFile(final File outputFile, final String data, final String encoding)

Description

Writes the given String data to the given output file, encoded using the given encoding.

License

Open Source License

Parameter

Parameter Description
outputFile File to save to (overwriting any existing content)
data String data to store

Exception

Parameter Description
IOException if the usual bad things happen
UnsupportedEncodingException if the given encodingis not supported.

Declaration

@Deprecated
public static void writeFile(final File outputFile, final String data, final String encoding)
        throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    /**//from   www . j a v a2s.  c  o m
     * Writes the given String data to the given output file, encoded using
     * the given encoding.
     *
     * @param outputFile File to save to (overwriting any existing content)
     * @param data String data to store
     *
     * @throws IOException if the usual bad things happen
     * @throws UnsupportedEncodingException if the given encoding
     *   is not supported.
     */
    @Deprecated
    public static void writeFile(final File outputFile, final String data, final String encoding)
            throws IOException {
        final FileOutputStream outStream = new FileOutputStream(outputFile);
        OutputStreamWriter writer = null;
        try {
            writer = new OutputStreamWriter(outStream, encoding);
            writer.write(data);
        } finally {
            if (writer != null) {
                writer.close();
            } else {
                outStream.close();
            }
        }
    }
}

Related

  1. writeFile(File path, String fileName, String fileContent)
  2. writeFile(File target, String content)
  3. writeFile(final byte[] content, final String path)
  4. writeFile(final File destination, final List contents)
  5. writeFile(final File f, final String content)
  6. writeFile(final String aText, final File aFile, final String aEncoding)
  7. writeFile(final String file, final String text)
  8. writeFile(final String name, final String s)
  9. writeFile(final String nameFile, final List listMsg)