Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Image loadImage(String offline, String online) {
- Image image = null;
- File file = new File(offline);
- if (!file.exists()) {
- URL url = null;
- try {
- url = new URL(online);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- InputStream is = null;
- try {
- is = url.openStream();
- } catch (IOException e) {
- e.printStackTrace();
- }
- OutputStream os = null;
- try {
- os = new FileOutputStream(file);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- byte[] b = new byte[2048];
- int length;
- try {
- while ((length = is.read(b)) != -1) {
- try {
- os.write(b, 0, length);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- os.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- try {
- image = ImageIO.read(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return image;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement