(五)IO流之ByteArrayInput/OutputStream
阿新 • • 發佈:2018-09-18
寫到 leo get io流 緩沖 out spa tput 字節
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