Client program:
Package Lgx.java.test;import Java.io.file;import Java.io.fileoutputstream;import java.io.ioexception;import Java.io.inputstream;import Org.apache.http.httpresponse;import Org.apache.http.client.httpclient;import Org.apache.http.client.methods.httpget;import Org.apache.http.impl.client.defaulthttpclient;public Class Httpclientget {/** * @param args */public static void main (string[] args) {//Use the Get method to connect to server HttpGet HttpGet = new HttpGet ("H Ttp://192.168.1.48:8080/test/test.jpg "); HttpClient client = new Defaulthttpclient (); FileOutputStream Fos;try {//client begins sending requests HttpResponse response = Client.execute (HttpGet) to the specified URL; inputstream inputstream = Response.getentity (). getcontent (); File File = new file ("D:\\jj"), if (!file.exists ()) {file.mkdirs ();} FOS = new FileOutputStream ("d:\\jj\\test.jpg"); byte[] data = new Byte[1024];int len = 0;while (len = inputstream.read (dat a))! =-1) {fos.write (data, 0, Len);}} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}
The server can refer to this article http://blog.csdn.net/harryweasley/article/details/45840523
Two articles similar, but one is the Java interface implementation, one is the Apache interface implementation
Connect to the server via Apache's httpclient get mode to download images to local