java _io_字节数组输入流
创建源:字节数组 不要太大
选择流: InputStream is =new ByteArrayInputStream(byte[] byte);
操作(输入)
无释放资源(使用.close()会是一个空方法,为了保证风格统一)
源头由文件(硬盘)换成字节数组:
因为字符数组是内存而不是文件(硬盘),所以java虚拟机可直接调用,由垃圾回收机制
(gc)来释放,所以无需手动.close()释放
public class test{ public static void main(String[]args) { //创建源 byte[] src="ad ad and".getBytes(); //选择流 InputStream is=null; try { is=new ByteArrayInputStream(src); byte[] flush=new byte[5]; //缓冲字符器 int len=-1; while((len=is.read(flush))!=-1) { String s=new String(flush,0,len); //解码,有字节到字符串 System.out.println(s); } }catch(IOException e) { e.printStackTrace(); }}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。