Java Text File Save writeFile(String str, String filename, boolean append)

Here you can find the source of writeFile(String str, String filename, boolean append)

Description

write File

License

Mozilla Public License

Declaration

public static void writeFile(String str, String filename, boolean append) throws IOException 

Method Source Code

//package com.java2s;
/***************************************************************************
 * Copyright (C) 2004, Patrick Charles and Jonas Lehmann                   *
 * Distributed under the Mozilla Public License                            *
 *   http://www.mozilla.org/NPL/MPL-1.1.txt                                *
 ***************************************************************************/

import java.io.FileWriter;

import java.io.IOException;

import java.io.FileOutputStream;

public class Main {
    public static void writeFile(String str, String filename, boolean append) throws IOException {

        int length = str.length();
        FileWriter out = new FileWriter(filename, append);
        out.write(str, 0, length);/*  w ww.j  a  va  2  s . c o m*/
        out.close();
    }

    public static void writeFile(byte[] bytes, String filename, boolean append) throws IOException {

        FileOutputStream out = new FileOutputStream(filename, append);
        out.write(bytes, 0, bytes.length);
        out.close();
    }

    public static void writeFile(byte[][] bytes, String filename, boolean append) throws IOException {

        writeFile(bytes[0], filename, append);
        for (int i = 1; i < bytes.length; i++)
            writeFile(bytes[i], filename, true);
    }

    public static void writeFile(byte[][] bytes, int beginIndex, int endIndex, String filename, boolean append)
            throws IOException {
        writeFile(bytes[beginIndex], filename, append);
        for (int i = beginIndex + 1; i <= endIndex; i++)
            writeFile(bytes[i], filename, true);
    }
}

Related

  1. writeFile(String ruta, String nombre, byte[] archivo)
  2. WriteFile(String sFileName, String content)
  3. writeFile(String sFileName, String sContent)
  4. writeFile(String sName, String data, String encoding)
  5. writeFile(String str, File f)
  6. writeFile(String string, File file)
  7. writeFile(String string, File location, boolean forceASCII)
  8. writeFile(String tailored, File f)
  9. writeFile(String targetPath, String filename, byte[] content)