Java ByteArrayOutputStream Write readAll(File file)

Here you can find the source of readAll(File file)

Description

read All

License

Open Source License

Declaration

public static byte[] readAll(File file) throws IOException 

Method Source Code


//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.io.BufferedInputStream;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static byte[] readAll(File file) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        copy(new BufferedInputStream(new FileInputStream(file)), baos);
        return baos.toByteArray();
    }// w ww  .j ava  2s .c  o m

    public static void copy(InputStream is, OutputStream os) throws IOException {
        try {
            byte[] buf = new byte[10240];
            int len;
            while ((len = is.read(buf)) != -1) {
                os.write(buf, 0, len);
            }
        } finally {
            os.close();
            is.close();
        }
    }
}

Related

  1. loadFully(final InputStream aStream)
  2. loadIfileAsBytes(final IFile ifile)
  3. loadIntoMemory(InputStream is)
  4. loadProbe(InputStream in, int buffSize)
  5. loadStream(InputStream in, String encoding)
  6. readAll(InputStream aInputStream)
  7. readAll(InputStream bytes)
  8. readAll(InputStream bytes, int bufferSize)
  9. readAll(InputStream in)