Util.java Source code

Java tutorial

Introduction

Here is the source code for Util.java

Source

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Util {
    public static byte[] readFile(String filename) throws IOException {
        File file = new File(filename);
        return readFile(file);
    }

    public static byte[] readFile(File file) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        int bytes = (int) file.length();
        byte[] buffer = new byte[bytes];

        int readBytes = bis.read(buffer);
        bis.close();
        return buffer;
    }

}