java.io.BufferedOutputStream.write(byte[] b, int off, int len)
import java.io.BufferedOutputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;publicclassBufferedOutputStreamDemo{publicstaticvoidmain(String[] args)throws Exception {
BufferedOutputStream bos = null;//此时的异常应该用try-catch-finallytry{// create new output streams.
baos =newByteArrayOutputStream();
bos =newBufferedOutputStream(baos);// assign values to the byte array byte[] bytes ={1,2,3,4,5};// write byte array to the output stream
bos.write(bytes,0,5);// flush the bytes to be written out to baos
bos.flush();for(byte b:baos.toByteArray()){// prints byte
System.out.print(b);}}catch(IOException e){// if any IOError occurs
e.printStackTrace();}finally{// releases any system resources associated with the streamif(baos!=null)
baos.close();if(bos!=null)
bos.close();}}}
java.io.BufferedInputStream.read(byte[] b, int off, int len)
import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.InputStream;publicclassBufferedInputStreamDemo{publicstaticvoidmain(String[] args)throws Exception {
InputStream inStream = null;
BufferedInputStream bis = null;//此时要用try-catch-finally来处理try{// open input stream test.txt for reading purpose.
inStream =newFileInputStream("c:/test.txt");// input stream is converted to buffered input stream
bis =newBufferedInputStream(inStream);// read number of bytes availableint numByte = bis.available();// byte array declaredbyte[] buf =newbyte[numByte];// read byte into buf , starts at offset 2, 3 bytes to read
bis.read(buf,2,3);// for each byte in buffor(byte b : buf){
System.out.println((char)b+": "+ b);}}catch(Exception e){
e.printStackTrace();}finally{// releases any system resources associated with the streamif(inStream!=null)
inStream.close();if(bis!=null)
bis.close();}}}
java.io.BufferedOutputStream.write(byte[] b, int off, int len)import java.io.BufferedOutputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;public class BufferedOutputStreamDemo { public static void main(String[] args) throw.