Java Utililty Methods File Content to Byte Array

List of utility methods to do File Content to Byte Array

Description

The list of methods to do File Content to Byte Array are organized into topic(s).

Method

byte[]getFileContentAsByteArray(String fileName)
get File Content As Byte Array
RandomAccessFile raf = new RandomAccessFile(fileName, "r");
Long lengthFile;
byte[] b;
raf.seek(0);
lengthFile = new Long(raf.length());
b = new byte[lengthFile.intValue()];
raf.readFully(b);
raf.close();
...
byte[]getFileContentAsByteArray(String fileName)
Returns the content of a given file as byte array.
RandomAccessFile raf = new RandomAccessFile(fileName, "r");
Long lengthFile;
byte[] b;
try {
    raf.seek(0);
    lengthFile = new Long(raf.length());
    b = new byte[lengthFile.intValue()];
    raf.readFully(b);
...
byte[]getFileContentAsBytes(String fileName)
Gets the file content as bytes.
FileInputStream is = new FileInputStream(fileName);
return getStreamContentAsBytes(is);
byte[]getFileContentAsBytes(String fileName)
get File Content As Bytes
FileInputStream is = new FileInputStream(fileName);
byte[] data = getStreamContentAsBytes(is);
is.close();
return data;
byte[]getFileContentByte(InputStream inputStream, long offset, int length)
get File Content Byte
if (offset < 0 || length < 0) {
    throw new Exception("getFileContent param error");
byte[] fileContent = null;
byte[] tempBuf = new byte[length];
inputStream.skip(offset);
int readLen = inputStream.read(tempBuf);
if (readLen < 0) {
...
byte[]getFileContentsAsByteArray(String filename)
Read in the contents of a file into a byte array
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
int len = (int) file.length();
byte[] bytes = new byte[len];
int bytesRead = 0;
int offset = 0;
while (offset < len) {
    bytesRead = fis.read(bytes, offset, len - offset);
...