package cn.text.one;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* @author pc
*操作步骤 1.创建源 2.选择流 3.操作 4.释放资源
*/
public class Text4 {
public static void main(String[] args) {
//字节数组输入流
InputStream in=null;
//转成字节数组(源头为字节数组)
byte[] src="take is cheap show me".getBytes();
try {
in=new ByteArrayInputStream(src);
//读取字节已K为单位 50K则程十。
byte[] flush=new byte[5];
int len=-1;
while((len=in.read(flush))!=-1) {
String str=new String(flush,0,len);
System.out.println(str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
//此处不用关闭文件ByteArrayInputStream 源文件中close()方法为空方法可有可无
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
IO-字节数组输入流
最新推荐文章于 2024-03-22 10:08:33 发布