List of utility methods to do File to Byte Array Read
byte[] | getBytes(File file) get Bytes FileInputStream inputStream = null; byte[] fileContent = null; try { inputStream = new FileInputStream(file); fileContent = new byte[(int) file.length()]; inputStream.read(fileContent); } catch (Exception e) { e.printStackTrace(); ... |
byte[] | getBytes(File file) get Bytes if (file == null || !file.exists()) { return null; ByteArrayOutputStream out = new ByteArrayOutputStream(); FileInputStream in = new FileInputStream(file); int c = in.read(); while (c != -1) { out.write(c); ... |
byte[] | getBytesFromFile(File file) get Bytes From File InputStream is = new FileInputStream(file); long length = file.length(); if (length > Integer.MAX_VALUE) { throw new IOException("File " + file.getName() + " is too large to process"); byte[] bytes = new byte[(int) length]; int offset = 0; ... |
byte[] | getBytesFromFile(File file, long startPostion, long numberOfBytesToRead) get Bytes From File try (FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream ous = new ByteArrayOutputStream()) { fis.skip(startPostion); byte[] dataBytes = new byte[BUFFER_SIZE]; long totalRead = 0; int nread = 0; while ((nread = fis.read(dataBytes)) != -1 && (totalRead <= numberOfBytesToRead || numberOfBytesToRead == -1)) { ... |
byte[] | getFileAsByteArray(File file) get File As Byte Array return getFileAsByteArrayOutputStream(file).toByteArray();
|
ByteArrayOutputStream | getFileAsByteArrayOutputStream( File file) get File As Byte Array Output Stream InputStream in = null; String tmpFilename = null; OutputStream out = null; byte[] buf = new byte[1024 * 8]; int len = 0; try { in = new FileInputStream(file); out = new ByteArrayOutputStream(); ... |
byte[] | readBytes(@NotNull File file) Reads the contents of a File into a byte[] .
int length = (int) file.length(); assert (length != 0); byte[] bytes = new byte[length]; int totalBytesRead = 0; FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); while (totalBytesRead != length) { ... |
byte[] | readBytes(@NotNull String filePath) Reads the contents of a File into a byte[] .
return readBytes(new File(filePath)); |
byte[] | readFileBytes(File fx) reads the content of a File and returns a byte array representing the content. FileInputStream fis; fis = new FileInputStream(fx); long length = fx.length(); byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = fis ... |
byte[] | readFileToByteArray(File file) read File To Byte Array byte[] fileBytes = new byte[(int) file.length()]; FileInputStream fis = null; try { fis = new FileInputStream(file); int offset = 0; int count = (int) file.length(); int temp = 0; while ((temp = fis.read(fileBytes, offset, count)) > 0) { ... |