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[]readFileAtOnce(final File file)
Reads the contents of the file at once and returns the byte array.
final FileInputStream fIn = new FileInputStream(file);
return readFileAtOnce(fIn);
byte[]readFileBinaries(File file)
read File Binaries
byte[] buffer = new byte[1024];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FileInputStream inputStream = new FileInputStream(file);
for (int readNum; (readNum = inputStream.read(buffer)) != -1;) {
    outputStream.write(buffer, 0, readNum);
inputStream.close();
return outputStream.toByteArray();
...
byte[]readFileBinary(String filename)
read File Binary
File file = new File(filename);
byte[] data = new byte[(int) file.length()];
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
dis.readFully(data);
dis.close();
return data;
byte[]readFileBytes(File file)
Read the file raw content into byte array.
if (file.exists() && file.isFile()) {
    FileInputStream fis = new FileInputStream(file);
    int fileLen = (int) file.length();
    byte[] buf = new byte[fileLen];
    int len = 0;
    while (len < fileLen) {
        int n = fis.read(buf, len, fileLen - len);
        if (n >= 0) {
...
byte[]readFileBytes(File file)
Returns the contents of file as a byte[].
InputStream istr = new FileInputStream(file);
byte bytes[] = new byte[istr.available()];
istr.read(bytes);
istr.close();
return bytes;
byte[]readFileBytes(String file)
read File Bytes
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedInputStream httpIn = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[1024];
int n;
while ((n = httpIn.read(buffer)) != -1)
    baos.write(buffer, 0, n);
httpIn.close();
return baos.toByteArray();
...
byte[]readFileBytes(String filename)
read File Bytes
File file = new File(filename);
InputStream is = new FileInputStream(file);
byte[] result = new byte[(int) file.length()];
int count = 0;
while (count < result.length) {
    int r = is.read(result, count, result.length - count);
    if (r < 0) {
        break;
...
byte[]readFileBytes(String fileName)
read File Bytes
File file = new File(fileName);
long length = file.length();
if (length > Integer.MAX_VALUE) {
    throw new IOException("File " + fileName + " is too large");
byte[] bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
...
byte[]readFileBytes(String filePath)
read File Bytes
InputStream fin = getFileInputStream(filePath);
byte[] b = new byte[1024];
int len = 0;
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
while ((len = fin.read(b)) != -1)
    bOut.write(b, 0, len);
return bOut.toByteArray();
StringreadFileEndAsString(File file, int size_limit)
read File End As String
return (readFileEndAsString(file, size_limit, "ISO-8859-1"));