Java FileOutputStream Write saveFile(String name, byte[] data)

Here you can find the source of saveFile(String name, byte[] data)

Description

Save data to a file.

License

Open Source License

Parameter

Parameter Description
name a parameter
data a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void saveFile(String name, byte[] data) throws IOException 

Method Source Code

//package com.java2s;
/*/*  w w w.  j av  a2s.  c o  m*/
 * OUnit - an OPAQUE compliant framework for Computer Aided Testing
 *
 * Copyright (C) 2010, 2011  Antti Andreimann
 *
 * This file is part of OUnit.
 *
 * OUnit 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 3 of the License, or
 * (at your option) any later version.
 *
 * OUnit 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 OUnit.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

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

public class Main {
    /**
     * Save data to a file. Creates parent directories if needed
     * 
     * @param name
     * @param data
     * @throws IOException
     */
    public static void saveFile(String name, byte[] data) throws IOException {
        saveFile(new File(name), data);
    }

    /**
     * Save data to a file. Creates parent directories if needed
     * 
     * @param dir
     * @param name
     * @param data
     * @throws IOException
     */
    public static void saveFile(File dir, String name, byte[] data) throws IOException {
        saveFile(new File(dir, name), data);
    }

    /**
     * Save data to a file. Creates parent directories if needed
     * 
     * @param file
     * @param data
     * @throws IOException
     */
    public static void saveFile(File file, byte[] data) throws IOException {
        if (file.getParentFile() != null)
            file.getParentFile().mkdirs();

        FileOutputStream fs = new FileOutputStream(file);
        fs.write(data);
        fs.close();
    }
}

Related

  1. saveFile(String filename, byte[] content)
  2. saveFile(String fileName, byte[] data)
  3. saveFile(String fileName, InputStream stream)
  4. saveFile(String filename, String content)
  5. saveFile(String fileName, String contents)
  6. saveFile(String path, byte[] content)
  7. saveFile(String pathFile, String data)
  8. saveFile(String pathname, String fileName, String contents)
  9. saveFile(String pathRoot, String subPath, boolean isFoler, InputStream in)