//string 转 byte[] String str = "问题"; byte[] srtbyte = str.getBytes(); // byte[] 转 string String res = new String(srtbyte); System.out.println(res);
当然还有可以设定编码方式的
String str = "问题"; byte[] srtbyte = null; try { srtbyte = str.getBytes("UTF-8"); String res = new String(srtbyte,"UTF-8"); System.out.println(res); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }
未经允许请勿转载:程序喵 » 【Java】byte数组和String字符串互相转换