在Java中可以通過如下方式實(shí)現(xiàn)String和bytes的相互轉(zhuǎn)換:
String hello ="Hello";
//轉(zhuǎn)成bytes
byte[] bytes = hello.getBytes();
//轉(zhuǎn)回來
String hello2 =new String(bytes);
在Dart中使用如下方式實(shí)現(xiàn)String和bytes的互轉(zhuǎn):
//dart中的字節(jié)流為int數(shù)組
// 轉(zhuǎn)成int數(shù)組
List<int> bytes = utf8.encode("Hello world");
print("bytes:$bytes");
// 轉(zhuǎn)回來
String r = utf8.decode(bytes);
print("result:$r");