import java
import java
import java
import
import
import
/*
* */
public class GetUrlImg {
public static void getUrlImg(String URLName
// target本地地址
int HttpResult =
URL url = new URL(URLName); //創建URL
URLConnection urlconn = url
HttpURLConnection httpconn = (HttpURLConnection) urlconn;
HttpResult = ();
System
if (HttpResult != HttpURLConnection
else {
int filesize = urlconn
BufferedInputStream bis=new BufferedInputStream(urlconn
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(target));
byte[] buffer = new byte[
int num =
while (true) {
num = bis
if (num ==
bos
break; //已經讀完
}
bos
bos
}
bos
bis
}
}
public static void main(String[] args) throws Exception{
GetUrlImg
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25804.html