[Java] Steam file Input stream

Source: Internet
Author: User

1  PackageTest.stream;2 3 ImportJava.io.FileInputStream;4 Importjava.io.FileNotFoundException;5 Importjava.io.IOException;6 /**7 * File input stream8  * @authorFrost.yen9 * @e-mail [email protected]Ten * @date April 13, 2016 One  */ A  Public classTESTSTREAM01 { -      Public Static voidMain (string[] args) { -         //1. Create a file input stream theFileInputStream FIS =NULL; -         Try { -FIS =NewFileInputStream ("E:\\java\\examples\\to Learn\\src\\test\\file\\testfile.java"); -             //2. Create a byte array to store the read information +             byte[] bt =New byte[1024]; -             //3. Using Len, the length of the read +             intLen = 0; A             //4. As long as Len >= 0 instructions are read to the element, you can manipulate the element directly at              while(Len=fis.read (BT)) >=0){ -                 //5. Output data through the console must indicate the length of the output -System.out.write (BT, 0, Len); -             } -             //6. The stream release resource must be closed after the read is completed - fis.close (); in}Catch(FileNotFoundException e) { - e.printstacktrace (); to}Catch(IOException e) { + e.printstacktrace (); -}finally { the             Try { *                 //Close the stream here $                 if(fis!=NULL) Fis.close ();Panax Notoginseng}Catch(IOException e) { - e.printstacktrace (); the             } +         } A     } the}

[Java] Steam file Input stream

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.