Java FileInputStream Read readFileInByteArray(String aFileName)

Here you can find the source of readFileInByteArray(String aFileName)

Description

faz a leitura de um arquivo especifico em um array de byte.

License

Open Source License

Parameter

Parameter Description
aFileName -> Nome do arquivo

Exception

Parameter Description
IOException an exception

Return

byte[]

Declaration

private static byte[] readFileInByteArray(String aFileName) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    /**/*from w  w w .  j  av a 2 s  . co m*/
     * faz a leitura de um arquivo especifico em um array de byte.
     * 
     * @param aFileName -> Nome do arquivo
     * @return byte[]
     * @throws IOException
     */
    private static byte[] readFileInByteArray(String aFileName) throws IOException {
        File file = new File(aFileName);
        FileInputStream fileStream = new FileInputStream(file);
        try {
            int fileSize = (int) file.length();
            byte[] data = new byte[fileSize];
            int bytesRead = 0;
            while (bytesRead < fileSize) {
                bytesRead += fileStream.read(data, bytesRead, fileSize - bytesRead);
            }
            return data;
        } finally {
            fileStream.close();
        }
    }
}

Related

  1. readFileBytes(String fileName)
  2. readFileBytes(String filePath)
  3. readFileEndAsString(File file, int size_limit)
  4. readFileEx(String... file)
  5. readFileFully(File file)
  6. readFileRaw(File file)
  7. readFileToBinary(File lessCSS)
  8. readFileToByteArray(File file)
  9. readFileToByteArray(File file)