title: Save java.awt.Image to disk in java
body: <p>I have read clob from oracle procedure and convert them into java.awt.Image object by the following code .</p>
  
  <pre><code>InputStream stream = clob.getAsciiStream();
                  ByteArrayOutputStream output = new ByteArrayOutputStream();
                  int a1 = stream.read();
                  while (a1 &gt;= 0) {
                    output.write((char) a1);
                    a1 = stream.read();
                  }
                  Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray());
                  output.close();
  </code></pre>
  
  <p>Now, I want to save myImage to hard disk. So, What must I do to save these java.awt.Image to file ?</p>
  
  <h2>My try :</h2>
  
  <p>I have cast the myImage to BufferedImage and then write this to ImageIo by the following code : </p>
  
  <pre><code>BufferedImage bi = (BufferedImage)myImage;
                 ImageIO.write(bi, "jpg",new File("E:\\out.jpg"));
  </code></pre>
  
  <p>But I am getting the following exception : </p>
  
  <pre><code>Got Exception as : sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage
  java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage
      at com.connect.home.Home.getHomeParameter(Home.java:103)
      at com.connect.home.Home.main(Home.java:141)
  </code></pre>
  
  <p>How can I remove this error ? Any advice is of great help . </p>