Java Text File Write nio writeTextFile(final File file, final String text)

Here you can find the source of writeTextFile(final File file, final String text)

Description

write Text File

License

BSD License

Declaration

public static void writeTextFile(final File file, final String text) throws Exception 

Method Source Code

//package com.java2s;
/**/*w  w w  .  j av  a  2  s .  c  o m*/
 * Copyright (C) 2010-2012 Andrei Pozolotin <Andrei.Pozolotin@gmail.com>
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */

import java.io.BufferedOutputStream;
import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;

public class Main {
    private static final Charset UTF_8 = Charset.forName("UTF-8");

    public static void writeTextFile(final File file, final String text) throws Exception {

        final OutputStream stream = new FileOutputStream(file);

        final BufferedOutputStream output = new BufferedOutputStream(stream);

        final OutputStreamWriter writer = new OutputStreamWriter(output, UTF_8);

        writer.write(text);

        writer.flush();

        writer.close();

    }
}

Related

  1. writeStringToFile(File file, String content, String value)
  2. writeStringToFile(File file, String string)
  3. writeStringToFile(File file, String text)
  4. writeStringToFile(final File file, final String content)
  5. writeStringToFile(String s, File f)
  6. writeTextFile(String file, String articleContent)
  7. writeTo(File file, String content)
  8. writeToFile(File file, String content)
  9. writeToFile(File file, String str)