java里面byte数组和String字符串怎么转换

2024-12-01 04:31:15
推荐回答(3个)
回答(1):

1、string 转 byte[]

String.getBytes(String decode)方法会根据指定的decode编码返回某字符串在该编码下的byte数组表示

String s= "Zhidao";

byte[] b= s.getBytes();

2、byte[] 转 string

直接通过构造函数,将byte[]数据转成string

byte[] b;
String s= new String(b);

回答(2):

byte--> String :s= new String(byte);
String-->byte: byte[] b=s.getBytes();

回答(3):

String s=new String(byte[]);