[英]Convert byte array to a string - - With Performace Android
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);
I'd like this method to return a String of the Byte values. 我想要此方法返回Byte值的字符串。 For example, it would be : "12,23,34 ...."
. 例如,它将是: "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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.