package cntext.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class text2 {
public static void main(String[] args) {
//字符数组输入流
//1.创建源 内部来维护
byte[] str=null;
//2.选择流 (新增方法)
ByteArrayOutputStream in=null;
in=new ByteArrayOutputStream();
//3.操作
String ing="你好,你是我最喜欢的小姐姐";
byte[] fulsh=ing.getBytes();
in.write(fulsh, 0, fulsh.length);
try {
in.flush();
//获取数据
fulsh=in.toByteArray();
System.out.println(fulsh.length+"--->"+new String(fulsh,0,in.size()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
in.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//释放资源可以不用 获取数据
}}
IO-字符数组输入流
最新推荐文章于 2023-10-13 11:30:08 发布