Here you can find the source of imageFromUrl(String url)
public static InputStream imageFromUrl(String url)
//package com.java2s; /*/* w w w .j ava2 s .c o m*/ * Copyright 2017 John Grosh <john.a.grosh@gmail.com>. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class Main { public static InputStream imageFromUrl(String url) { if (url == null) return null; try { URL u = new URL(url); URLConnection urlConnection = u.openConnection(); urlConnection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"); return urlConnection.getInputStream(); } catch (IOException | IllegalArgumentException e) { } return null; } }