Java Dump File dumpToFile(String fileName, String buffer, boolean append)

Here you can find the source of dumpToFile(String fileName, String buffer, boolean append)

Description

dump To File

License

Apache License

Declaration

public static void dumpToFile(String fileName, String buffer, boolean append) 

Method Source Code

//package com.java2s;
/*//  w  ww .  ja  v a 2s  .  c  o m
 * Licensed to Eolya and Dominique Bejean under one
 * or more contributor license agreements. 
 * Eolya licenses this file to you under the 
 * Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

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

import java.io.FileOutputStream;

import java.io.FileWriter;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    public static void dumpToFile(String fileName, String buffer, boolean append) {
        dumpToFile(fileName, buffer, append, "");
    }

    public static void dumpToFile(String fileName, String buffer, boolean append, String encoding) {
        try {
            if (!"".equals(encoding)) {
                BufferedWriter out = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(new File(fileName)), encoding));
                out.write(buffer);
                out.close();
            } else {
                BufferedWriter writer = null;
                writer = new BufferedWriter(new FileWriter(fileName, append));
                writer.write(buffer);
                writer.close();
            }
        } catch (IOException e) {
            // e.printStackTrace();
            System.err.println(e);
        }
    }
}

Related

  1. dumpFile(final Reader rdr)
  2. dumpFile(String filename)
  3. dumpFile(String filename)
  4. dumpToFile(String dest, String content)
  5. dumpToFile(String name, String string)
  6. dumptoTempFile(List lineItems)
  7. dumpToTemporaryFile(String modifiedSource, String modifiedPythonFile)