Java FileInputStream Read readFileRaw(File file)

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

Description

read File Raw

License

BSD License

Declaration

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

Method Source Code

//package com.java2s;
/***//from  w w  w . j a  v  a  2  s.  com
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */

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

import java.io.IOException;

public class Main {
    public static byte[] readFileRaw(File file) throws IOException {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        FileInputStream is = new FileInputStream(file);
        byte[] buf = new byte[1024];
        int ret;
        while ((ret = is.read(buf)) != -1)
            os.write(buf, 0, ret);
        is.close();
        return os.toByteArray();
    }
}

Related

  1. readFileBytes(String filePath)
  2. readFileEndAsString(File file, int size_limit)
  3. readFileEx(String... file)
  4. readFileFully(File file)
  5. readFileInByteArray(String aFileName)
  6. readFileToBinary(File lessCSS)
  7. readFileToByteArray(File file)
  8. readFileToByteArray(File file)
  9. readFileToByteArray(File file)