Created
April 26, 2012 14:11
-
-
Save Cakemix1337/2499877 to your computer and use it in GitHub Desktop.
getImage method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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