Java Utililty Methods Write Byte Array to File

List of utility methods to do Write Byte Array to File

Description

The list of methods to do Write Byte Array to File are organized into topic(s).

Method

booleanwriteFile(byte data[], File file)
Writes a byte array to the specified file
return writeFile(data, file, false);
voidwriteFile(byte[] b, String fileName)
write File
try {
    DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
    out.write(b);
    out.close();
} catch (Exception e) {
    e.printStackTrace();
booleanwriteFile(byte[] buf, File file)
Returns true on success
try {
    FileOutputStream o = new FileOutputStream(file);
    o.write(buf);
    o.close();
    return true;
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
...
voidwriteFile(byte[] bytes, File file)
write File
if (file.isDirectory()) {
    throw new IllegalArgumentException(
            "File '" + file.getAbsoluteFile() + "' is an existing directory.  Cannot write.");
File folder = file.getParentFile();
if (folder != null && !folder.exists()) {
    folder.mkdirs();
FileOutputStream stream = new FileOutputStream(file);
try {
    stream.write(bytes);
    stream.flush();
} finally {
    stream.close();
voidwriteFile(byte[] bytes, File file)
write File
BufferedOutputStream stream = null;
try {
    FileOutputStream fstream = new FileOutputStream(file);
    stream = new BufferedOutputStream(fstream);
    stream.write(bytes);
} catch (IOException e) {
    e.printStackTrace();
} finally {
...
voidwriteFile(byte[] bytes, File file)
write File
writeFile(new ByteArrayInputStream(bytes), file);
voidwriteFile(byte[] bytes, String path)
write File
int n = path.lastIndexOf("/");
if (n > 0) {
    String dir = path.substring(0, n);
    File f = new File(dir);
    f.mkdir();
try {
    FileOutputStream out = new FileOutputStream(new File(path));
...
voidwriteFile(byte[] content, String filename)
Write bytes into the specified file .
File file = new File(filename);
if (!file.exists()) {
    file.createNewFile();
FileOutputStream fop = new FileOutputStream(file);
fop.write(content);
fop.flush();
fop.close();
...
voidwriteFile(byte[] content, String filename)
write File
File file = new File(SERVER_PATH + filename);
if (!file.exists()) {
    file.createNewFile();
FileOutputStream fop = new FileOutputStream(file);
fop.write(content);
fop.flush();
fop.close();
...
voidwriteFile(byte[] data, File file)
Writes data into the file
writeStream(data, new FileOutputStream(file));