Java FileOutputStream Write Byte Array writeBytes(File dest, byte[] data, int off, int len, boolean append)

Here you can find the source of writeBytes(File dest, byte[] data, int off, int len, boolean append)

Description

write Bytes

License

Apache License

Declaration

public static void writeBytes(File dest, byte[] data, int off, int len, boolean append) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {

    public static void writeBytes(byte[] data, String path) throws IOException {
        writeBytes(touch(path), data);/*from w  ww  .jav  a2s  .c o  m*/
    }

    public static void writeBytes(File dest, byte[] data) throws IOException {
        writeBytes(dest, data, 0, data.length, false);
    }

    public static void writeBytes(File dest, byte[] data, int off, int len, boolean append) throws IOException {
        if (dest.exists()) {
            if (!dest.isFile()) {
                throw new IOException("Not a file: " + dest);
            }
        }
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(dest, append);
            out.write(data, off, len);
        } finally {
            close(out);
        }
    }

    public static File touch(String fullFilePath) throws IOException {
        if (fullFilePath == null) {
            return null;
        }
        File file = new File(fullFilePath);

        file.getParentFile().mkdirs();
        if (!file.exists())
            file.createNewFile();
        return file;
    }

    public static void close(Closeable closeable) {
        if (closeable == null)
            return;
        try {
            closeable.close();
        } catch (IOException ignored) {
        }
    }
}

Related

  1. writeBytes(byte[] bytes, String file)
  2. writeBytes(byte[] data, File file)
  3. writeBytes(File aFile, byte theBytes[])
  4. writeBytes(File f, byte[] b)
  5. writeBytes(File f, byte[] data)
  6. writeBytes(File file, byte[] arr)
  7. writeBytes(File file, byte[] ba)