/**
* 把二進位制檔案轉化為位元組陣列
* @param path :path of specified file
* @return bytes[]
* @throws Exception
*/
public static byte[] toByteArrFromFile(String path) throws Exception{
File inFile = new File(path);
FileInputStream fileInputStream = new FileInputStream(inFile);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
//轉化為位元組陣列流
while ((i = fileInputStream.read()) != -1) {
byteArrayOutputStream.write(i);
}
fileInputStream.close();
// 把檔案存在一個位元組陣列中
byte[] bytes = byteArrayOutputStream.toByteArray();
byteArrayOutputStream.close();
return bytes;
/**
* 把二進位制檔案轉化為位元組陣列
* @param path :path of specified file
* @return bytes[]
* @throws Exception
*/
public static byte[] toByteArrFromFile(String path) throws Exception{
File inFile = new File(path);
FileInputStream fileInputStream = new FileInputStream(inFile);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
//轉化為位元組陣列流
while ((i = fileInputStream.read()) != -1) {
byteArrayOutputStream.write(i);
}
fileInputStream.close();
// 把檔案存在一個位元組陣列中
byte[] bytes = byteArrayOutputStream.toByteArray();
byteArrayOutputStream.close();
return bytes;
}