Java将byte转换成图片并保存在本地

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

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

public class TestTime {

 /**
  * @param args
  */
 public static void main(String[] args)throws Exception {
  String url = null;
  url="http://www.baidu.com/img/baidu_sylogo1.gif";      //可以通过爬虫得到图片连接
  HttpClient httpClient = new HttpClient();
  GetMethod getMethod = new GetMethod(url);
  httpClient.executeMethod(getMethod);               //执行getMrthod
  byte[] responseBody = getMethod.getResponseBody();
  OutputStream out = new FileOutputStream(new File("D:\\"+1+".jpg"));
  out.write(responseBody);
     out.flush();
     System.out.println("download success");
     out.close();

 }
}

你可能感兴趣的:(HtmlParser)