将文件转成byte[]文件属组

/**
     * 
     *  @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;  
    }
原文地址:https://www.cnblogs.com/yy123/p/5195845.html