Java FileOutputStream Write Byte Array writeBytes(File file, byte[] source, int offset, int len)

Here you can find the source of writeBytes(File file, byte[] source, int offset, int len)

Description

write Bytes

License

Apache License

Declaration

public static void writeBytes(File file, byte[] source, int offset, int len) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static void writeBytes(String filename, byte[] source) throws IOException {
        if (source == null) {
            return;
        }/*w ww. java2 s .  co m*/
        writeBytes(new File(filename), source, 0, source.length);
    }

    public static void writeBytes(File file, byte[] source) throws IOException {
        if (source == null) {
            return;
        }
        writeBytes(file, source, 0, source.length);
    }

    public static void writeBytes(String filename, byte[] source, int offset, int len) throws IOException {
        writeBytes(new File(filename), source, offset, len);
    }

    public static void writeBytes(File file, byte[] source, int offset, int len) throws IOException {
        if (len < 0) {
            throw new IOException("File size is negative!");
        }
        if (offset + len > source.length) {
            len = source.length - offset;
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            fos.write(source, offset, len);
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
    }
}

Related

  1. writeBytes(File file, byte[] bytes)
  2. writeBytes(File file, byte[] bytes)
  3. writeBytes(File file, byte[] bytes, boolean append)
  4. writeBytes(File file, byte[] data)
  5. writeBytes(File file, byte[] pattern, int repeat)
  6. writeBytes(File filename, byte[] contents)
  7. writeBytes(File outputFile, byte[] bytes)
  8. writeBytes(final File file, final byte[] bytes)
  9. writeBytes(final File file, final byte[] bytes)