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

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

Description

Writes data to a file.

License

Open Source License

Parameter

Parameter Description
filename The filename. Can be '-' for writing to stdout.
data The data to write.

Exception

Parameter Description
IOException When write fails.

Declaration

public static void writeFile(final String filename, final byte[] data) throws IOException 

Method Source Code

//package com.java2s;
/*//  w  w w.j  a v  a  2 s. c o m
 * Copyright (C) 2011 Klaus Reimer <k@ailis.de>
 * See LICENSE.md for licensing information.
 */

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

import java.io.OutputStream;

public class Main {
    /**
     * Writes data to a file.
     *
     * @param filename
     *            The filename. Can be '-' for writing to stdout.
     * @param data
     *            The data to write.
     * @throws IOException
     *             When write fails.
     */
    public static void writeFile(final String filename, final byte[] data) throws IOException {
        if (filename.equals("-")) {
            System.out.write(data);
            return;
        }

        try (final OutputStream stream = new FileOutputStream(filename)) {
            stream.write(data);
        }
    }
}

Related

  1. getOutputStream(String theFilePath)
  2. getOutputStreamForFile(final File file)
  3. getOutputStreamForFile(String filename)
  4. writeFile(File outFile, ZipInputStream zipInputStream, ZipEntry entry)
  5. writeFile(FileOutputStream fileoutputstream, byte abyte0[], int i)
  6. writeFile(final String fileNamePath, final byte[] daten)
  7. writeFile(InputStream in, File file)
  8. writeFile(InputStream inputFile, String path, String fullFileName)
  9. writeFile(InputStream inputStream, String filename, long lastModified)