Java File Write nio writeFile(String name, String content)

Here you can find the source of writeFile(String name, String content)

Description

write File

License

Open Source License

Declaration

public static void writeFile(String name, String content) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedWriter;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;

public class Main {
    public static void writeFile(String name, String content) {
        Writer writer = null;/*from   w w  w  . jav a 2 s .c  om*/
        try {
            writer = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(name), Charset.defaultCharset()));
            writer.write(content);
        } catch (IOException ex) {
            // report
        } finally {
            try {
                writer.close();
            } catch (Exception ex) {
                /*ignore*/}
        }
    }
}

Related

  1. writeFile(OutputStream file, List data)
  2. writeFile(String filename, byte file[])
  3. writeFile(String fileName, String content)
  4. writeFile(String fileName, String content)
  5. writeFile(String folder, String aFileName, String aItem)