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(String filename)
read File
File file = new File(filename);
long len = file.length();
byte data[] = new byte[(int) len];
FileInputStream fin = new FileInputStream(file);
int r = fin.read(data);
if (r != len)
    throw new IOException("Only read " + r + " of " + len + " for " + file);
fin.close();
...
StringreadFile(String fileName)
read File
StringBuffer sbuf = new StringBuffer();
FileInputStream reader = null;
try {
    byte[] buf = new byte[2048];
    reader = new FileInputStream(fileName);
    int read = -1;
    while ((read = reader.read(buf)) != -1) {
        sbuf.append(new String(buf, 0, read));
...
byte[]readFile(String fileName)
read File
FileInputStream is = new FileInputStream(fileName);
byte[] b = null;
try {
    b = new byte[is.available()];
    is.read(b);
} finally {
    is.close();
return b;
StringreadFile(String filename)
read File
File f = new File(filename);
InputStream stream = null;
try {
    stream = new FileInputStream(f);
} catch (FileNotFoundException e1) {
    e1.printStackTrace();
int ch = 0;
...
StringreadFile(String fileName)
DOCUMENTME.
byte[] cont = null;
File file = new File(fileName);
FileInputStream fi = new FileInputStream(file);
try {
    long len = file.length();
    cont = new byte[(int) len];
    fi.read(cont);
} finally {
...
byte[]readFile(String filename)
read File
FileInputStream file = new FileInputStream(filename);
byte[] data = new byte[(int) file.available()];
file.read(data);
file.close();
return data;
StringreadFile(String filename)
read File
FileInputStream in = new FileInputStream(filename);
return readContents(in);
byte[]readFile(String filename)
read File
FileInputStream fis = new FileInputStream(filename);
try {
    return getByteArrayFromStream(fis);
} finally {
    fis.close();
byte[]readFile(String fileName)
Reads the named file, translating IOException to a RuntimeException of some sort.
File file = new File(fileName);
return readFile(file);
PropertiesreadFile(String fileName)
read File
File f = new File(fileName);
if (!f.exists()) {
    throw new IllegalArgumentException("No such file: " + f.getCanonicalPath());
FileInputStream in = null;
try {
    Properties prop = new Properties();
    in = new FileInputStream(f);
...