Here you can find the source of readFileInByteArray(String aFileName)
Parameter | Description |
---|---|
aFileName | -> Nome do arquivo |
Parameter | Description |
---|---|
IOException | an exception |
private static byte[] readFileInByteArray(String aFileName) throws IOException
//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(); } } }