import javaioBufferedInputStream;
import javaioBufferedOutputStream;
import javaioFileOutputStream;
import HttpURLConnection;
import URL;
import URLConnection;
/* *读取网络照片保存到本地
* */
public class GetUrlImg {
public static void getUrlImg(String URLNameString target) throws Exception {//URLName照片地址
// target本地地址
int HttpResult = ; //服务器返回的状态
URL url = new URL(URLName); //创建URL
URLConnection urlconn = urlopenConnection(); // 试图连接并取得返回状态码nnect();
HttpURLConnection httpconn = (HttpURLConnection) urlconn;
HttpResult = ();
Systemoutprintln(HttpResult);
if (HttpResult != HttpURLConnectionHTTP_OK) // 不等于HTTP_OK说明连接不成功Systemoutprint(fail);
else {
int filesize = urlconngetContentLength(); // 取数据长度Systemoutprintln(filesize);
BufferedInputStream bis=new BufferedInputStream(urlconngetInputStream());
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(target));
byte[] buffer = new byte[]; //创建存放输入流的缓沖
int num = ; //读入的字节数
while (true) {
num = bisread(buffer); // 读入到缓沖区
if (num ==){
bosflush();
break; //已经读完
}
bosflush();
boswrite(buffernum);
}
bosclose();
bisclose();
}
}
public static void main(String[] args) throws Exception{
GetUrlImggetUrlImg();
}
}