Java Fundamentals Hardening IO Stream Note 29:bufferedoutputstream/bufferedinputstream (byte buffer stream) Bufferedinputstream read data

Source: Internet
Author: User

1. Bufferedinputstream reading data

Bufferedinputstream construction method, as follows:

Construction Method Summary
BufferedInputStream(InputStream in)
Create one BufferedInputStream and save its arguments, that is, the input stream for in future use.
BufferedInputStream(InputStream in, int size)
creates a specified buffer size BufferedInputStream and saves its arguments, that is, the input stream for in future use.

2. code example:

1  Packagecn.itcast_05;2 3 ImportJava.io.BufferedInputStream;4 ImportJava.io.FileInputStream;5 Importjava.io.IOException;6 7 /*8 * Note: Although we have two ways to read, note that both of these methods can only be used in one code for the same object. 9  */Ten  Public classBufferedinputstreamdemo { One      Public Static voidMain (string[] args)throwsIOException { A         //Bufferedinputstream (InputStream in) -Bufferedinputstream bis =NewBufferedinputstream (NewFileInputStream ( -"Bos.txt")); the  -         //reading Data -         //int by = 0; -         //While (by = Bis.read ())! =-1) { +         //System.out.print ((char) by); -         // } +         //System.out.println ("---------"); A  at         byte[] Bys =New byte[1024]; -         intLen = 0; -          while(len = Bis.read (bys))! =-1) { -System.out.print (NewString (bys, 0, Len)); -         } -  in         //Freeing Resources - bis.close (); to     } +}

Run the effect as follows:

Java Fundamentals Hardening IO Stream Note 29:bufferedoutputstream/bufferedinputstream (byte buffer stream) Bufferedinputstream read data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.