Java OutputStreamWriter Write saveFile(File file, String whatToSave, String encoding)

Here you can find the source of saveFile(File file, String whatToSave, String encoding)

Description

save File

License

Open Source License

Declaration

public static void saveFile(File file, String whatToSave, String encoding) 

Method Source Code

//package com.java2s;
//License from project: Open Source 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 saveFile(File file, String whatToSave) {
        saveFile(file, whatToSave, "UTF8");
    }//from   ww  w .ja  v  a 2 s.c  om

    public static void saveFile(File file, String whatToSave, String encoding) {
        if (file.isDirectory()) {
            throw new IllegalArgumentException("File " + file + " should not be a directory");
        }

        try {
            BufferedWriter output = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(file), encoding));
            output.write(whatToSave);
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. save(String fileContent, File file, String encoding)
  2. save(String text, File out)
  3. saveCache()
  4. saveDocument(String path, String textToWrite)
  5. saveFile(final File file, final String content)
  6. saveFile(String content, File f, String encoding)
  7. saveFile(String fname, String text, String encode)
  8. saveFile(String path, String msg)