public static void main(String[] args) throws IOException { String a="babbabababbababababab"; byte[] buff = new byte[1024]; //从字符串获取字节写入流 InputStream is = new ByteArrayInputStream(a.getBytes("utf-8")); System.out.println(is); int len = -1; while(-1 != (len = is.read(buff))) { //将字节数组转换为字符串 String res = new String(buff, 0, len); System.out.println(res); } }
字符串和字节流相互转换
最新推荐文章于 2024-07-30 17:42:39 发布