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

如题所述

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);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-04-25
byte--> String :s= new String(byte);
String-->byte: byte[] b=s.getBytes();本回答被提问者采纳
第2个回答  2016-04-25
String s=new String(byte[]);