title: ImageIO write method - javax imageio IIOException Cant create output stream
body: <pre><code>protected void doGet(HttpServletRequest req, HttpServletResponse response)
          throws IOException, ServletException {
      // Expire response
      try {
          //   
          ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();
          byte[] captchaBytes;
  
          BufferedImage image = new BufferedImage(width, height,
                  BufferedImage.TYPE_INT_RGB);
          Graphics2D graphics2D = image.createGraphics();
          Hashtable&lt;TextAttribute, Object&gt; map = new Hashtable&lt;TextAttribute, Object&gt;();
          Random r = new Random();
          String token = Long.toString(Math.abs(r.nextLong()), 36);
          String ch = token.substring(0, 6);
          Color c = new Color(0.6662f, 0.4569f, 0.3232f);
          GradientPaint gp = new GradientPaint(30, 30, c, 15, 25,
                  Color.white, true);
          graphics2D.setPaint(gp);
          Font font = new Font("Verdana", Font.CENTER_BASELINE, 26);
          graphics2D.setFont(font);
          graphics2D.drawString(ch, 2, 22);
          graphics2D.dispose();
  
          HttpSession session = req.getSession(true);
          session.setAttribute(CAPTCHA_KEY, ch);
  
          OutputStream outputStream = response.getOutputStream();
          ImageIO.write(image, "jpeg", imgOutputStream);
          captchaBytes = imgOutputStream.toByteArray();
          response.setHeader("Cache-Control", "no-cache");
          response.setDateHeader("Expires", 0);
          response.setHeader("Pragma", "no-cache");
          response.setDateHeader("Max-Age", 0);
          response.setContentType("image/jpeg");
          outputStream.write(captchaBytes);
          outputStream.close();
          utils.PQSoftLogger.getInstance().log(
                  "Captch servlet: " + image.toString());
      } catch (Exception e) {
          utils.PQSoftLogger.getInstance().log(
                  e.toString() + ":" + e.getMessage());
          for (StackTraceElement s : e.getStackTrace()) {
              utils.PQSoftLogger.getInstance().log(
                      s.getLineNumber() + ":" + s.getMethodName() + ":"
                              + s.getFileName());
          }
      } finally {
          utils.PQSoftLogger.getInstance().log("temp dir-"+System.getProperty("java.io.tmpdir"));
          utils.PQSoftLogger.getInstance().log("Captch servlet executed");
      }
  }
  </code></pre>
  
  <p>following exception is thrown on <code>ImageIO.write</code> method when calling the servlet on tomcat server environment but it is working will on local system.</p>
  
  <p><strong><code>javax.imageio.IIOException: Can't create output stream!</code></strong></p>