标签:class ring write close col you while 文件 get
ByteArrayInputStream:是把字节数组当成源的输入流
String string="hello shanghai"; ByteArrayInputStream bis=new ByteArrayInputStream(string.getBytes()); int data=-1; while ((data=bis.read())!=-1) { System.out.print((char)data); } //bis.close();
ByteArrayInputStream:是把字节数组当做目标的输出流
ByteArrayOutputStream bos=new ByteArrayOutputStream(); bos.write(97); bos.write("hello world".getBytes()); byte[] buff=bos.toByteArray(); for(byte data:buff) { System.out.println((char)data); } FileOutputStream fos=new FileOutputStream("D:\\aa.txt",true); bos.writeTo(fos);//把 ByteArrayOutputStream内部缓冲区的数据写到对应的文件输出流中 fos.close();
(五)IO流之ByteArrayInput/OutputStream
标签:class ring write close col you while 文件 get
原文地址:https://www.cnblogs.com/tanlei-sxs/p/9665425.html