Java Utililty Methods FileInputStream Read

List of utility methods to do FileInputStream Read

Description

The list of methods to do FileInputStream Read are organized into topic(s).

Method

byte[]readFile(File f)
Read a (small) file into a byte array.
DataInputStream dis = null;
try {
    dis = new DataInputStream(new FileInputStream(f));
    byte[] ret = new byte[(int) f.length()];
    dis.readFully(ret);
    dis.close();
    return ret;
} finally {
...
intreadFile(File f, int fetchLength, byte[] bytes)
read File
InputStream fileStream = new FileInputStream(f);
fetchLength = fileStream.read(bytes, 0, bytes.length);
fileStream.close();
return fetchLength;
byte[]readFile(File f, int iChunkSize)
Converts a file into a byte array.
if (iChunkSize < 1)
    iChunkSize = 4096;
try {
    FileInputStream fin = new FileInputStream(f);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(iChunkSize);
    byte buf[] = new byte[iChunkSize]; 
    while (fin.available() > 0) {
        int iRead = fin.read(buf);
...
byte[]readFile(File file)
read File
byte[] data = null;
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int br;
while ((br = bis.read(buffer)) > 0) {
    baos.write(buffer, 0, br);
...
byte[]readFile(File file)
Reads the given file, translating IOException to a RuntimeException of some sort.
return readFile(file, 0, -1);
byte[]readFile(File file)
Returns an array of bytes read from the specified file
if (file == null) {
    return null;
} else if (!file.exists()) {
    return null;
} else {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(file);
...
StringreadFile(File file)
read File
BufferedInputStream bin = null;
StringBuilder builder = new StringBuilder();
try {
    FileInputStream fin = new FileInputStream(file);
    bin = new BufferedInputStream(fin);
    byte[] contents = new byte[1024];
    int bytesRead = 0;
    while ((bytesRead = bin.read(contents)) != -1) {
...
byte[]readFile(File file)
Reads the given file, translating IOException to a RuntimeException of some sort.
if (!file.exists()) {
    throw new RuntimeException(file + ": file not found");
if (!file.isFile()) {
    throw new RuntimeException(file + ": not a file");
if (!file.canRead()) {
    throw new RuntimeException(file + ": file not readable");
...
byte[]readFile(File file)
Reads entire file into byte array.
assert file.exists();
assert file.length() < Integer.MAX_VALUE;
byte[] bytes = new byte[(int) file.length()];
try (FileInputStream fis = new FileInputStream(file)) {
    int readBytesCnt = fis.read(bytes);
    assert readBytesCnt == bytes.length;
return bytes;
...
byte[]readFile(File file)
read File
FileInputStream fis = new FileInputStream(file);
try {
    int fileLen = fis.available();
    if (fileLen > MAX_MEDIA_FILE_LENGTH) {
        return null;
    byte[] data = new byte[fileLen];
    fis.read(data);
...