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