Exception thrown while converting large sized jpg images
<p>I am trying to <strong>upload the jpg</strong> images &amp; converting same into new <strong>thumbnail</strong> through servlet.
After writing that file on disk, my requirment is to create a thumbnail for the same jpg file.
And for that I used following code...</p>

<pre><code>//code to upload &amp; write image file on disk goes here..

BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
img.createGraphics().drawImage(ImageIO.read(new File(sourceFile)).getScaledInstance(100, 100, Image.SCALE_SMOOTH),0,0,null);

ImageIO.write(img, "jpg", new File(thumbFile));
</code></pre>

<p>Above code <strong>goes well for small files</strong>. But when its comes towards file of size <strong>5MB</strong>, it copies, but fails to convert it into thumbnail &amp; throws </p>

<pre><code>Exception in thread ""http-bio-8888"-exec-63" java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferByte.&lt;init&gt;(Unknown Source)
    at java.awt.image.ComponentSampleModel.createDataBuffer(Unknown Source)
    at java.awt.image.Raster.createWritableRaster(Unknown Source)
    at javax.imageio.ImageTypeSpecifier.createBufferedImage(Unknown Source)
    at javax.imageio.ImageReader.getDestination(Unknown Source)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
    at javax.imageio.ImageIO.read(Unknown Source)
    at javax.imageio.ImageIO.read(Unknown Source)
    at UploadFile.doPost(UploadFile.java:67).
</code></pre>

<p>Please guide me.</p>
