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 destination)
readFile
File temp = new File(destination);
if (temp.exists()) {
    FileInputStream fis = new FileInputStream(temp);
    byte[] data = new byte[(int) temp.length()];
    try {
        fis.read(data);
    } finally {
        fis.close();
...
StringreadFile(String file)
read File
File log = new File(file);
FileInputStream fis;
BufferedInputStream bis;
String content = "";
try {
    fis = new FileInputStream(log);
    bis = new BufferedInputStream(fis);
    int bytes = bis.available();
...
StringreadFile(String file)
Really too bad assertThat(file).hasContent(String) didn't work with intellij idea to show me specific diffs.
try {
    FileInputStream fis = new FileInputStream(file);
    StringBuffer fileContent = new StringBuffer("");
    byte[] buffer = new byte[1024];
    int n;
    while ((n = fis.read(buffer)) != -1) {
        fileContent.append(new String(buffer, 0, n));
    return fileContent.toString();
} catch (IOException e) {
    throw new RuntimeException(e);
StringreadFile(String file)
read File
int len = (int) (new File(file)).length();
FileInputStream fis = new FileInputStream(file);
byte buf[] = new byte[len];
fis.read(buf);
fis.close();
return new String(buf);
byte[]readFile(String file)
read File
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int read;
while ((read = fis.read(buff)) != -1) {
    baos.write(buff, 0, read);
baos.flush();
...
StringreadFile(String file)
read File
FileInputStream in = null;
String content = "";
try {
    File f = new File(file);
    in = new FileInputStream(file);
    int c = (int) f.length();
    byte[] contentBytes = new byte[c];
    in.read(contentBytes);
...
byte[]readFile(String file)
Read File and return byte[]
FileInputStream fis = new FileInputStream(new File(file));
byte[] data = new byte[fis.available()];
fis.read(data);
fis.close();
return data;
byte[]readFile(String filename)
read File
return readFile(new File(filename));
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);
...
StringreadFile(String fileName)
read File
FileInputStream reader = null;
try {
    reader = new FileInputStream(fileName);
    byte[] fileBytes = new byte[reader.available()];
    reader.read(fileBytes);
    return new String(fileBytes);
finally {
...