public static int copyStream(InputStream sourceStream,OutputStream destinationStream) throws IOException {
  int bytesRead=0;
  int totalBytes=0;
  byte[] buffer=new byte[1024];
  while (bytesRead >= 0) {
    bytesRead=sourceStream.read(buffer,0,buffer.length);
    if (bytesRead > 0) {
      destinationStream.write(buffer,0,bytesRead);
    }
    totalBytes+=bytesRead;
  }
  destinationStream.flush();
  destinationStream.close();
  return totalBytes;
}

public static int copyStream ( InputStream sourceStream , OutputStream destinationStream ) throws IOException { int bytesRead = 0 ; int totalBytes = 0 ; byte [ ] buffer = new byte [ 1024 ] ; while ( bytesRead >= 0 ) { bytesRead = sourceStream . read ( buffer , 0 , buffer . length ) ; if ( bytesRead > 0 ) { destinationStream . write ( buffer , 0 , bytesRead ) ; } totalBytes += bytesRead ; } destinationStream . flush ( ) ; destinationStream . close ( ) ; return totalBytes ; }
copies the data from an inputstream object to an outputstream object .
