Java Text File Save writeFile(String path, String text)

Here you can find the source of writeFile(String path, String text)

Description

write File

License

Apache License

Declaration

private static void writeFile(String path, String text) throws IOException 

Method Source Code

//package com.java2s;
/**//www. java2s .  c  om
   @license http://www.apache.org/licenses/LICENSE-2.0
   @author Goetz Hatop 
   @title Simple Utility Class to wrap Filesystem access
   @date 2013-01-18
*/

import java.io.IOException;

import java.io.Writer;
import java.io.BufferedWriter;

import java.io.OutputStreamWriter;

import java.io.FileOutputStream;
import java.io.FileNotFoundException;

public class Main {
    private static void writeFile(String path, String text) throws IOException {
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"));
            out.write(text);
        } catch (FileNotFoundException e) {
            //throw new IOException(e.toString()); 
        } finally {
            if (out != null)
                out.close();
        }
    }

    public static void write(String path, String text) {
        try {
            writeFile(path, text);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. writeFile(String path, String contents)
  2. writeFile(String path, String data)
  3. writeFile(String path, String fileName, String content)
  4. writeFile(String path, String fileName, String content, String charset)
  5. writeFile(String path, String fileName, String data)
  6. writeFile(String path, String text)
  7. writeFile(String path, String text, boolean orverWite)
  8. writeFile(String path, Vector contents)
  9. writeFile(String pContent, String pPath)