Java FileOutputStream Create writeFile(String path, byte[] data)

Here you can find the source of writeFile(String path, byte[] data)

Description

Write whole data to a file.

License

Open Source License

Parameter

Parameter Description
path the path of a file.
data data to write.

Return

true if success, false on failure.

Declaration

public static boolean writeFile(String path, byte[] data) 

Method Source Code

//package com.java2s;
/*************************************************************************************************
 * Class of utility methods/* w w  w . j a va  2 s. c o  m*/
 *                                                      Copyright (C) 2000-2006 Mikio Hirabayashi
 * This file is part of QDBM, Quick Database Manager.
 * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
 * Lesser General Public License as published by the Free Software Foundation; either version
 * 2.1 of the License or any later version.  QDBM 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 Lesser General Public License for more
 * details.
 * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
 * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA.
 *************************************************************************************************/

import java.io.IOException;

import java.io.OutputStream;

import java.io.FileOutputStream;

public class Main {
    /**
     * Write whole data to a file.
     * @param path the path of a file.
     * @param data data to write.
     * @return true if success, false on failure.
     */
    public static boolean writeFile(String path, byte[] data) {
        OutputStream os = null;
        try {
            os = new FileOutputStream(path);
            os.write(data);
        } catch (IOException e) {
            return false;
        } finally {
            try {
                if (os != null)
                    os.close();
            } catch (IOException e) {
            }
        }
        return true;
    }
}

Related

  1. writeFile(String filePath, byte[] bytes)
  2. writeFile(String filePath, Object obj)
  3. writeFile(String filePathName, Object obj)
  4. writeFile(String p_filename, String p_buffer)
  5. writeFile(String path, byte[] contents)
  6. writeFile(String path, Properties store, String comment)
  7. writeFile(ZipEntry entry, ZipFile zipFile, File file)
  8. writeFile0(File file, CharSequence content, Iterable lines)
  9. writeFileAsBytes(String fullPath, byte[] bytes)