字节数组转换为字符串 - - 随着服务表现的Andr​​oid数组、字符串、转换为、字节

2023-09-03 23:15:51 作者:你不配﹌

Bitmap foto = b.getBitmap();

byte[] bytes = null;
ByteArrayOutputStream ba = new ByteArrayOutputStream();
foto.compress(Bitmap.CompressFormat.JPEG, 100, ba);
foto.recycle();
foto = null;

bytes = ba.toByteArray();

String bBytes = Arrays.toString(bytes);

我想这个方法返回字节值的字符串。例如,这将是:12,23,34 ......

推荐答案

下面是你如何能做到这一点。

Here is how you can do it.

import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        byte[] bytes = {1,2,3,12};
        String bBytes = Arrays.toString(bytes);
        bBytes = bBytes.replaceAll(" ", "");
        bBytes = bBytes.replaceAll("\\[", "");
        bBytes = bBytes.replaceAll("\\]", "");
        System.out.println(bBytes);     
    }

}