import java.io.*;
import java.net.*;
public class URLGetPhoto
{
public static void main(String [] args)
{
URL url=null;
File f=new File("E:\\danke");
f.mkdir();
try
{
int count=0;
int i=11;
String str=String.valueOf(0)+String.valueOf(0)+String.valueOf(0)+String.valueOf(0);
while(i!=1001)
{
if(i>=10)
str=String.valueOf(0)+String.valueOf(0);
if(i>=100)
str=String.valueOf(0);
try
{
url=new URL("http://model.avl.com.cn/world/baby/anzu/images/01"+str+i+".jpg");
InputStream uin=url.openStream();
BufferedInputStream in=new BufferedInputStream(uin);
FileOutputStream fio=new FileOutputStream("e:\\danke\\"+str+i+".jpg");
BufferedOutputStream osw=new BufferedOutputStream(new DataOutputStream(fio));
int b;
byte[] a=new byte[1024];
while((b=in.read(a))!=-1)
{
osw.write(a,0,b);
osw.flush();
count+=b;
System.out.println(b);
}
i++;
}
catch(Exception ee)
{
System.out.println("first"+ee);
i++;
continue;
}
}
int by=count/1024;
int bm=by/1024;
System.out.println("共接收"+by+'K'+bm+'M');
}
catch(Exception e)
{
System.out.println("last"+e);
}
}
}
本文地址:http://com.8s8s.com/it/it9995.htm