Java Write String to File writeFile(File f, String content)

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

Description

write File

License

Apache License

Declaration

public static void writeFile(File f, String content) throws Exception 

Method Source Code

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

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    public static void writeFile(File f, String content) throws Exception {
        BufferedWriter writer = null;
        try {/*  w w  w . j a va 2 s.  c o  m*/
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
            writer.write(content);
        } catch (Exception e) {
            throw e;
        } finally {
            if (writer != null) {
                try {
                    writer.flush();
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. writeFile(File f, String body)
  2. writeFile(File f, String content)
  3. writeFile(File f, String content, String encoding)
  4. writeFile(File f, String contents)
  5. writeFile(File f, String entry)