Connect to the server via Apache's httpclient get mode to download images to local

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.