ファイルをbyte[]ファイル属グループに変換
1993 ワード
/**
*
* @Description :
* @Method_Name : fileBuff
* @param filePath
* @return
* @throws IOException
* @return : byte[]
* @Creation Date : 2015 1 27 5:26:49
* @Author :
*/
public static byte[] fileBuff(String filePath) throws IOException {
File file = new File(filePath);
long fileSize = file.length();
if (fileSize > Integer.MAX_VALUE) {
//System.out.println("file too big...");
return null;
}
FileInputStream fi = new FileInputStream(file);
byte[] file_buff = new byte[(int) fileSize];
int offset = 0;
int numRead = 0;
while (offset < file_buff.length && (numRead = fi.read(file_buff, offset, file_buff.length - offset)) >= 0) {
offset += numRead;
}
//
if (offset != file_buff.length) {
throw new IOException("Could not completely read file "
+ file.getName());
}
fi.close();
return file_buff;
}