java 字符流与字节流互转

时间:2022-08-28 15:06:36
package test;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; public class IOZhuanHuan { public static void main(String[] args) throws IOException {
// TODO 自动生成的方法存根
String src="你好啊!";
InputStream is=new ByteArrayInputStream(src.getBytes("utf-8"));//字符流转字节流 BufferedReader in=new BufferedReader(new InputStreamReader(is,"utf-8"));//字节转字符
System.out.println(in.readLine());
} }