Packagecn.itcast.io.c.bytestream.test;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classCopyfilebybuffertest {/** * @paramargs *@throwsIOException*/ Public Static voidMain (string[] args)throwsIOException {File srcfile=NewFile ("E:\\1.mp3"); File DestFile=NewFile ("E:\\copy_1.mp3"); //2, explicit byte stream input stream and source associated, output stream and destination association. FileInputStream FIS =NewFileInputStream (srcfile); FileOutputStream Fos=NewFileOutputStream (destfile); //3, define a buffer. byte[] buf =New byte[1024]; intLen = 0; while(len = Fis.read (BUF))! =-1) {fos.write (buf,0, Len);//writes data of the specified length in the array to the output stream. } //4, close the resource. Fos.close (); Fis.close (); }}
"IO Stream" 16-byte stream-Custom buffered array copy file