code: public void sendFile(File file, OutputStream os) throws IOException {
          FileInputStream is = null;
          BufferedInputStream buf = null;;
          try {
              is = new FileInputStream(file);
              buf = new BufferedInputStream(is);
              int readBytes = 0;
              if (LOGGER.isDebugEnabled()) {
                  LOGGER.debug("Writing file...");
              }
              while ((readBytes = buf.read()) != -1) {
                  os.write(readBytes);
              }
              os.flush();
              if (LOGGER.isDebugEnabled()) {
                  LOGGER.debug("File written");
              }
          } finally {
              if (is != null) {
                  is.close();
              }
              if (buf != null) {
                  buf.close();
              }
          }
      }
docs: Write a file to an OuputStream.
  
  @param file File that will be written.
  @param os The target OutputStream.
  @throws IOException if any error happens.