16进制字符串转成16进制数组

	BLE项目中涉及到读取文件格式为16进制,
	读取到的字符串为16进制,
	如:“C0FE008A00C5”,
	让他转换为byte[],形式如byte[0xC0,0xFE,0x00,0x8A,0x00,0xC5]这样子。

//读取文件
	  public void readFile() {
    InputStream is = null;

    try {
        is = mContext.getResources().openRawResource(R.raw.bb);
        int temp;
        int i = 0;
        byte[] fileBuffer = new byte[5];
        while (i < 5) {
            temp = is.read();
            String s = String.format("%02X", temp);
            fileBuffer[i]=(byte) Integer.parseInt(s, 16);
            i++;
        }
            sendMassage(fileBuffer);
        //Log.e(TAG,s);

    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }


}

你可能感兴趣的:(java)