http下载图片

来源:互联网 发布:sem和seo区别aso 编辑:程序博客网 时间:2024/05/22 01:44

模拟http请求下载网络图片:

要导入commons-httpclient-3.1.jar包。

package com.base.utils;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;


public class DownloadPic {
/**
* @param args
* @throws IOException 
* @throws HttpException 
*/
public static void main(String[] args) throws HttpException, IOException {
// TODO Auto-generated method stub
HttpClient client=new HttpClient();
GetMethod get=new GetMethod("http://kf.bsoft.com.cn:81/upload/Requirement/05999/059990163613/201410101400428761.jpg");
client.executeMethod(get);
File storeFile=new File("d:/hehe.jpg");
FileOutputStream s=new FileOutputStream(storeFile);
s.write(get.getResponseBody());
s.close();
}
}

0 0
原创粉丝点击