Java FileOutputStream Write saveStringToFile(File file, String content, String charset)

Here you can find the source of saveStringToFile(File file, String content, String charset)

Description

Saves specified content to the file with specified charset.

License

Open Source License

Parameter

Parameter Description
file a parameter
content a parameter
charset a parameter

Exception

Parameter Description
IOException an exception
UnsupportedEncodingException an exception

Declaration

public static void saveStringToFile(File file, String content, String charset) throws IOException 

Method Source Code

//package com.java2s;

import java.io.*;

public class Main {
    /**/*  w  w w  . j  a v  a2  s . c  o m*/
     * Saves specified content to the file with specified charset.
     *
     * @param file
     * @param content
     * @param charset
     * @throws IOException
     * @throws UnsupportedEncodingException
     */
    public static void saveStringToFile(File file, String content, String charset) throws IOException {
        FileOutputStream out = new FileOutputStream(file);
        byte[] data = content.getBytes(charset);

        out.write(data);

        out.flush();
        out.close();
    }
}

Related

  1. saveStreamToFile(InputStream in, File outFile)
  2. saveStreamToFile(InputStream is, File destFile)
  3. saveStringIntoFile(File file, String contents)
  4. saveStringIntoFile(String filePath, String contents)
  5. saveStringsList(String file, Collection c)
  6. saveTemp(final byte[] data, final String suffix)
  7. saveTempFile(String xmlSource, String fileName)
  8. saveTextContentInFile(String content, File file)
  9. saveTextToFile(String fileName, String content)