生活随笔
收集整理的這篇文章主要介紹了
字节缓冲流构造方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
-
字節緩沖流介紹
-
構造方法:
方法名說明
| BufferedOutputStream(OutputStream out) | 創建字節緩沖輸出流對象 |
| BufferedInputStream(InputStream in) | 創建字節緩沖輸入流對象 |
-
示例代碼
public class BufferStreamDemo {public static void main(String[] args) throws IOException {//字節緩沖輸出流:BufferedOutputStream(OutputStream out)BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("myByteStream\\bos.txt"));//寫數據bos.write("hello\r\n".getBytes());bos.write("world\r\n".getBytes());//釋放資源bos.close();//字節緩沖輸入流:BufferedInputStream(InputStream in)BufferedInputStream bis = new BufferedInputStream(new FileInputStream("myByteStream\\bos.txt"));//一次讀取一個字節數據
// int by;
// while ((by=bis.read())!=-1) {
// System.out.print((char)by);
// }//一次讀取一個字節數組數據byte[] bys = new byte[1024];int len;while ((len=bis.read(bys))!=-1) {System.out.print(new String(bys,0,len));}//釋放資源bis.close();}
}
?
總結
以上是生活随笔為你收集整理的字节缓冲流构造方法的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。