import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
public class TestDownLoadImage {
public static void main(String[] args) {
String url="http://wx1.sinaimg.cn/mw690/006sl6kBgy1fel3aq0nyej30i20hxq7i.jpg";
String downToFilePath="d:/download/image/";
String fileName="test";
imageDownLoad(url, downToFilePath,fileName);
}
public static void imageDownLoad(String urlString, String filepath,String filename) {
InputStream is =null;
ImageInputStream iis=null;
OutputStream os =null;
String downloadPath=null;
try {
URL url = new URL(urlString);
URLConnection con = url.openConnection();
is = con.getInputStream();
iis=ImageIO.createImageInputStream(is);
Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
if (!iter.hasNext()) {
return ;
}
ImageReader reader = iter.next();
//读文件格式jpg 等
String imgFormat=reader.getFormatName();
byte[] bs = new byte[1024];
int len;
File file=new File(filepath);
if(!file.exists()){
file.mkdir();
}
downloadPath=filepath+"//"+filename+"."+imgFormat;
报错javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
最新推荐文章于 2025-04-26 12:18:28 发布