Java FileOutputStream Write Byte Array writeBytesToFile(byte[] data, String path)

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

Description

write Bytes To File

License

Open Source License

Return

true on success.

Declaration

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

Method Source Code


//package com.java2s;
/*/*from w w w.j  a  v a  2s . co  m*/
 * This program 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.
 */

import java.io.*;

public class Main {
    /**
     *   @return      true on success.
     */
    public static boolean writeBytesToFile(byte[] data, String path) {
        if (path != null) {
            return writeBytesToFile(data, new File(path));
        }

        return false;
    }

    /**
     *   @return      true on success.
     */
    public static boolean writeBytesToFile(byte[] data, File file) {
        try {
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(data);
            fos.close();

            return true;
        } catch (IOException ioe) {
            return false;
        }
    }
}

Related

  1. writeBytesSafely(File aFile, byte theBytes[])
  2. writeBytesToFile(byte[] bfile, String filePath, String fileName)
  3. writeBytesToFile(byte[] byteContent, String fileName)
  4. writeBytesToFile(byte[] bytes, File file)
  5. writeBytestoFile(byte[] bytes, String filepath)
  6. writeBytesToFile(File destination, byte[] bytes)
  7. writeBytesToFile(File file, byte[] bytes)
  8. writeBytesToFile(File theFile, byte[] bytes)
  9. writeBytesToFile(final byte[] data, String filename)