1. Сохранить на сервере
Сохраните его на сервере, где проект находится в соответствии с пути.
String imgurl = ""; // Адрес изображения try {// construct url url url = new url (imgurl); // Открыть соединение urlConnection con = url.openconnection (); // Входной поток inputstream IS = con.getInputStream (); // 1K Bufpering Boftement Byte [] bs = новый байт [1024]; // Читать длину данных int len; // Выходной поток файла outputStream OS = new FileOutputStream ("c: //image.jpg"); // Сохранить путь // Начать чтение while ((len = is.read (bs))! = -1) {os.write (bs, 0, len); } // Завершите, закройте все ссылки os.close (); is.close (); } catch (malformedurlexception e) {e.printstacktrace (); } catch (filenotFoundException e) {e.printstackTrace (); } catch (ioException e) {e.printstackTrace (); }2. Сохранить в местном
Сохраните локально как загрузка браузера.
String imgurl = ""; // url -адрес string fileename = imgurl.substring (imgurl.lastindexof ('/') + 1); BufferedInputStream IS = NULL; BufferedOutputStream OS = NULL; try {url url = new url (imgurl); this.getServletresponse (). setContentType ("Application/x-msdownload;"); this.getServletResponse (). Setheader ("Content-Disposition", "ATTHAMENT; FILENAME =" + new String (fileName.getBytes ("UTF-8"), "ISO8859-1")); this.getServletResponse (). Setheader ("Content-Dength", String.valueof (url.openconnection (). getContentLength ())); is = new BufferedInputStream (url.OpenStream ()); OS = New BufferedOutputStream (this.getServletresponse (). getOutputStream ()); byte [] buff = new Byte [2048]; int bytesread; while (-1! = (bytesread = is.read (buff, 0, buff.length))) {os.write (buff, 0, bytesread); } if (is! = null) is.close (); if (os! = null) os.close (); } catch (malformedurlexception e) {e.printstacktrace (); } catch (unsupportEncodingexception e) {e.printstacktrace (); } catch (ioException e) {e.printstackTrace (); }Приведенный выше простой пример загрузки изображений на клиенты и серверы на основе URL -адресов - это весь контент, которым я делюсь с вами. Я надеюсь, что вы можете дать вам ссылку, и я надеюсь, что вы сможете поддержать Wulin.com больше.