Java FileOutputStream Create writeFileAsBytes(String fullPath, byte[] bytes)

Here you can find the source of writeFileAsBytes(String fullPath, byte[] bytes)

Description

Write an array of bytes to a file.

License

Open Source License

Declaration

public static void writeFileAsBytes(String fullPath, byte[] bytes) throws IOException 

Method Source Code

//package com.java2s;
/**/*from ww  w .j  av  a  2 s . c  o m*/
 * Copyright 2010, Alvin Alexander, http://devdaily.com.
 * This software is distributed under the terms of the 
 * GNU General Public License.
 *
 * This file is part of an application named JustWrite.
 *
 * JustWrite 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.
 *
 * JustWrite 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 JustWrite. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.io.*;

public class Main {
    /**
     * Write an array of bytes to a file. Presumably this is binary data; for plain text
     * use the writeFile method.
     */
    public static void writeFileAsBytes(String fullPath, byte[] bytes) throws IOException {
        OutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(fullPath));
        InputStream inputStream = new ByteArrayInputStream(bytes);
        int token = -1;

        while ((token = inputStream.read()) != -1) {
            bufferedOutputStream.write(token);
        }
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
        inputStream.close();
    }
}

Related

  1. writeFile(String path, byte[] contents)
  2. writeFile(String path, byte[] data)
  3. writeFile(String path, Properties store, String comment)
  4. writeFile(ZipEntry entry, ZipFile zipFile, File file)
  5. writeFile0(File file, CharSequence content, Iterable lines)
  6. writeFileAsString(final File filePath, final String output, final String charset)
  7. writeFileAsString(String filename, String contents)
  8. writeFileBinary(String filename, byte[]... dataArrays)
  9. writeFileByBytes(String content, String filename)