1、使用 new URL()
ImageIO.read(new URL(url));
获取图片有限制,可以读取图片的格式 :[BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF, gif]
获取不到图片时返回为null,后续操作可能会报空指针
2、通过流的方式获取
public BufferedImage getUrlImage(String url) { byte[] bytes = HttpsUtils.getBytes(url); InputStream buffin = new ByteArrayInputStream(bytes,0,bytes.length); BufferedImage img = null; try { img = ImageIO.read(buffin); } catch (IOException e) { e.printStackTrace(); } return img; }