Summary: Call the stream in finally{}. Close (); Ensure that the flow pipeline is finally closed.
ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;/** * @authorCzchina **/ Public classTeststream { Public Static voidMain (string[] args) {FileInputStream fis=NULL; FileOutputStream Fos=NULL; Try{FIS=NewFileInputStream ("E:/android/androidstudioprojects/text.txt"); FOS=NewFileOutputStream ("E:/android/androidstudioprojects/store.txt"); //generating a byte array byte[] buffer=New byte[500]; while(true){ intTMP = Fis.read (buffer,0, buffer.length); if(-1 = =tmp) {System.out.print ("Read Complete! \ n "); Break; } fos.write (Buffer,0, TMP); } } Catch(Exception e) {System.out.println (e); } finally{ Try{fis.close (); Fos.close (); } Catch(Exception e) {System.out.println (e); } } }}
Console
Java Foundation-Stream pipeline shutdown-flow. Close ();