Java Fundamentals Hardening IO Stream Note 27:fileinputstream reading data one byte array at a time byte[]

Source: Internet
Author: User

1. FileInputStream reading data One byte array at a time byte[]

Use FileInputStream to read one byte array at a time:

int read (byte[] b)

  return value : The return value is actually the number of bytes actually read.

2. code example:

1  PackageCom.himi.fileinputstream;2 3 ImportJava.io.FileInputStream;4 Importjava.io.IOException;5 6 7 8 /**9  * Ten * Use FileInputStream one byte array at a time: int read (byte[] b) One * Return value: The return value is actually the number of bytes actually read A  *  -  */ -  the  -  Public classFileInputStreamDemo1 { -  -      Public Static voidMain (string[] args)throwsIOException { +FileInputStream FIS =NewFileInputStream ("A.txt"); -     //Development Time final version code +         byte[] Bys =New byte[1024]; A         intLen = 0; at          while(len = Fis.read (bys))! =-1) { -System.out.print (NewString (bys,0, Len)); -         } -          -     } -  in}

Run the effect as follows:

Java Fundamentals Hardening IO Stream Note 27:fileinputstream reading data one byte array at a time byte[]

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.