Skip to content

Instantly share code, notes, and snippets.

@Cakemix1337
Created April 26, 2012 14:11
Show Gist options
  • Save Cakemix1337/2499877 to your computer and use it in GitHub Desktop.
Save Cakemix1337/2499877 to your computer and use it in GitHub Desktop.
getImage method
public Image getImage(String URL, String location) {
Image image = null;
try {
if(!location.endsWith("/") && !location.endsWith("\\") && !location.trim().empty())
location.concat("/");
URL url = new URL(URL);
File file = new File(location + url.getFile());
if (!file.exists()) {
ImageIO.write(ImageIO.read(url), url.getFile().replaceAll(".*?([^\\.]+)$", "$1"), file);
}
image = ImageIO.read(file);
} catch (MalformedURLException ex) {
return null;
} catch (IOException ex) {
return null;
}
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment