Java Write String to File writeFile(String fileName, String contentStr, String charset)

Here you can find the source of writeFile(String fileName, String contentStr, String charset)

Description

write File

License

Open Source License

Declaration

public static void writeFile(String fileName, String contentStr, String charset)
            throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*//from   w w w . j ava  2s.c o m
 * Copyright (C) 2014 hu
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.io.File;

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

public class Main {
    public static void writeFile(String fileName, String contentStr, String charset)
            throws FileNotFoundException, IOException {
        byte[] content = contentStr.getBytes(charset);
        FileOutputStream fos = new FileOutputStream(fileName);
        fos.write(content);
        fos.close();
    }

    public static void writeFile(File file, String contentStr, String charset)
            throws FileNotFoundException, IOException {
        byte[] content = contentStr.getBytes(charset);
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(content);
        fos.close();
    }

    public static void writeFile(String fileName, byte[] content) throws FileNotFoundException, IOException {
        FileOutputStream fos = new FileOutputStream(fileName);
        fos.write(content);
        fos.close();
    }

    public static void writeFile(File file, byte[] content) throws FileNotFoundException, IOException {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(content);
        fos.close();
    }
}

Related

  1. writeFile(String filename, String content)
  2. writeFile(String fileName, String content, String encoding)
  3. writeFile(String fileName, String contents)
  4. writeFile(String fileName, String contents)
  5. writeFile(String filename, String contents)
  6. writeFile(String fileName, String data)
  7. writeFile(String filename, String data)
  8. writeFile(String FileName, String data)
  9. writeFile(String fileName, String encoding, String content)