How to print raw byte content from a byte[] array to stdout in Java?

前端 未结 2 1181
梦毁少年i
梦毁少年i 2020-12-09 17:52

I am doing the same project as describe here:

Wrap deflated data in gzip format

My problem is that when I try to print out bytes, I get weird results. My pro

2条回答
  •  孤城傲影
    2020-12-09 18:48

     /* There is an image / ic_launcher in the drawable folder for which I am making ByteArray   */
    
    
    
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.img);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] mByteArray = stream.toByteArray();
    

    /* here I am showing the raw data not in hexadecimal format */

        System.out.println(Arrays.toString(mByteArray));
    

    I think this will help you guys!

提交回复
热议问题