Copying an image from url using java
<p>I am trying to download an image from URL. I use the <em>Apache Commons</em> library: </p>

<pre><code>org.apache.commons.io.FileUtils
                .copyURLToFile(
                        new URL(
                                "https://lh3.ggpht.com/AXYMUV5cpne2vE9U3X8x87HgrbwijwiG50_yOnehU2MUPKDoJky-BKFOPZzZ07Pug8U=h230"),
                        new File("test.png"));
</code></pre>

<p>While opening the image it says not an PNG file. Is this a good way to download images from url to local?</p>

<p>Updated .
Thankyou guys for your answers i undestand that i need to get the <code>connection.getContentType();</code> and then save it as jpg or png as it is.</p>
