public class StreamFromString {
static String src = "今天的天气真的不好";
public static void main(String[] args) throws IOException {
byte[] buff = new byte[1024];
//从字符串获取字节写入流
InputStream is = new ByteArrayInputStream(src.getBytes("utf-8"));
int len = -1;
while(-1 != (len = is.read(buff))) {
//将字节数组转换为字符串
String res = new String(buff, 0, len);
System.out.println(res);
}
}
}
字符串与字节流转换
最新推荐文章于 2024-07-15 02:39:50 发布