1. Guarde al servidor
Guárdelo en el servidor donde el proyecto se encuentra de acuerdo con la ruta.
Cadena imgurl = "" "; // dirección de imagen prueba {// construir url url url = new url (imgurl); // Abrir conexión urlconnection con = url.openconnection (); // Input Stream InputStream es = Con.getInputStream (); // 1k Buffing de datos Byte [] bs = nuevo byte [1024]; // Leer longitud de datos int Len; // El archivo de salida de la transmisión de la transmisión OutStream OS = new FileOutputStream ("c: //image.jpg"); // Guardar ruta // Inicie la lectura while ((len = is.read (bs))! = -1) {os.write (bs, 0, len); } // Completa, cierre todos los enlaces OS.Close (); is.close (); } catch (malformedurexception e) {E.PrintStackTrace (); } catch (FileNotFoundException e) {E.PrintStackTrace (); } catch (ioException e) {E.PrintStackTrace (); }2. Guarde al local
Guarde localmente como descarga de un navegador.
Cadena imgurl = ""; // URL Dirección String FileName = imgurl.substring (imgurl.lastIndexof ('/') + 1); BufferedInputStream es = nulo; BufferedOutputStream OS = null; intente {url url = new url (imgurl); this.getServletResponse (). SetContentType ("Aplicación/X-MSDload;"); this.getServletResponse (). Setheader ("Content-Disposition", "Attachment; FileName =" + New String (FileName.getBytes ("UTF-8"), "ISO8859-1")); this.getServletResponse (). Setheader ("Content-Length", 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 (malformedurexception e) {E.PrintStackTrace (); } catch (UnsupportedEncodingException e) {E.PrintStackTrace (); } catch (ioException e) {E.PrintStackTrace (); }El simple ejemplo simple de descargar imágenes a clientes y servidores basados en URL es todo el contenido que comparto con usted. Espero que pueda darle una referencia y espero que pueda apoyar más a Wulin.com.