io中的字节数组输入流和字节数组输出流的区别
字节数组输入流:
1,创建源 是一个字节数组
2,选择流 ByteArrayInputStream()
3,操作
4,可以不用关闭 gc自动回收 不需要通过os
字节数组输出流
1,不需要创建源
2,选择流 ByteArrayOutputStream()
3,操作 需注意的是在内存中想要显示它,用toByteArray()
4,可以不用关闭 gc自动回收 不需要通过os
package cn.com.io;
import java.io.*;
public class TestIo07 {
public static void main(String[] args) {
//字节数组输入流
//1 创建源 字节数组
//2 选择流 ByteArrayInputStream()
//3 操作
//4 可以不用关闭
byte[] bytes = "talk is cheap show me the code".getBytes();
InputStream is = new ByteArrayInputStream(bytes);
byte[] flush = new byte[3];
int tmp;
try {
while((tmp = is.read(flush)) != -1) {
String str = new String(flush,0,tmp);
System.out.println(str);
}
}catch(IOException e) {
e.