Java简单实现远程资源图片下载功能

mac2025-04-17  3

String imgeUrl="远程图片的URL地址"; BufferedImage bufferedImage=null; try { URL url=new URL(imgeUrl); URLConnection urlConnection=url.openConnection(); HttpURLConnection httpURLConnection=(HttpURLConnection)urlConnection; httpURLConnection.connect(); if (httpURLConnection.getResponseCode()== HttpURLConnection.HTTP_OK){ InputStream inputStream=httpURLConnection.getInputStream(); bufferedImage=ImageIO.read(inputStream); //参数二设置保存图片的格式 //参数三设置图片保存地址 ImageIO.write(bufferedImage,"png",new File("/work/888888.png")); }else { System.out.println("连接失败"); } } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); }

 

最新回复(0)