The example of this article tells the method of downloading pictures from the Internet to the local area from the Internet. Share it for everyone for your reference. The specifics are as follows:
Import java.io.*; Import Java.net.malfmeDurlexception; Import Java.net.url; Public Static Void WritFile (String Filename) {UR. L url = null; try {url = new url (strurl);} catch (MalFormedurlexception E2) {e2.printstacktrace ();} inputStream is = null; try {is = url.openstream (); race ();} outputStream OS = NULL; File F = New File ("d: // webimg //"); f.mkdirs (); try {os = new fileoutstream ("d: // webimg //"+filename); int BytesRead = 0; byte [] buffer = new byte [8192]; While ((bytesRead = Is.read (buffer, 0,8192))! =-1) {OS.Write (buffer, 0, bytesRead);}} Catch IoException e) {e.printstacktrace ();}}
It is hoped that this article is helpful to everyone's Java program design.