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 file, int size)
Reads some bytes from the file.
byte[] b = new byte[size];
FileInputStream fin = null;
try {
    fin = new FileInputStream(file);
    fin.read(b, 0, size);
} finally {
    if (fin != null) {
        fin.close();
...
intreadFile(File file, OutputStream output)
read File
FileInputStream fis = null;
try {
    fis = new FileInputStream(file);
    return copy(fis, output);
} finally {
    fis.close();
StringreadFile(File file, String encoding)
read File
return readFile(new FileInputStream(file), encoding);
StringreadFile(File file, String encoding)
read File
InputStream is = new FileInputStream(file);
long length = file.length();
if (length > Integer.MAX_VALUE) {
byte[] bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
...
StringBuilderreadFile(File file, String encoding)
read File
if (encoding == null)
    encoding = "UTF-8";
StringBuilder sb = new StringBuilder();
if (!file.exists() || !file.isFile())
    return sb;
final int buffer = 1024;
byte[] bs = new byte[buffer];
FileInputStream in = new FileInputStream(file);
...
byte[]readFile(File fyl)
Read a file.
int len = (int) fyl.length();
byte[] bfr = new byte[len];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fyl));
bis.read(bfr, 0, len);
bis.close();
return bfr;
byte[]readFile(File path)
read File
int length = (int) path.length();
byte[] content = new byte[length];
InputStream inStream = new FileInputStream(path);
try {
    inStream.read(content);
} finally {
    inStream.close();
return content;
Stringreadfile(File path)
readfile
String resp = "";
FileInputStream inp;
try {
    inp = new FileInputStream(path);
    byte[] bf = new byte[(int) path.length()];
    inp.read(bf);
    resp = new String(bf, "UTF-8");
    inp.close();
...
byte[]readFile(File source)
read File
if (!source.exists()) {
    throw new FileNotFoundException(source.getAbsolutePath());
if (!source.canRead()) {
    throw new IOException("cannot read " + source);
if (source.isDirectory()) {
    throw new IOException("source is a directory: " + source);
...
byte[]readFile(File src)
read File
java.io.FileInputStream fin = new java.io.FileInputStream(src);
try {
    long fileLen = src.length();
    if (fileLen > Integer.MAX_VALUE)
        throw new IOException("file length too big to be read by FileUtil.readFile: " + fileLen);
    byte[] bytes = new byte[(int) fileLen];
    fin.read(bytes);
    return bytes;
...