java,
分享于 点击 25999 次 点评:152
java,
一个从网络拷贝图片的例子public class DownLoad {
public void downLoad() throws FileNotFoundException, IOException{
HttpURLConnection httpUrl = null;
File writefile=new File("C:/Users/Netstar/Desktop/hua.jpg");
URL ul=new URL("http://a.hiphotos.baidu.com/image/w%3D1920%3Bcrop%3D0%2C0%2C1920%2C1080/sign=ed3a62cf9b25bc312b5d05916cefb6d2/d6ca7bcb0a46f21f7ec6e952f4246b600d33aec5.jpg");
httpUrl=(HttpURLConnection) ul.openConnection();
httpUrl.connect();
BufferedInputStream bis = new BufferedInputStream(httpUrl.getInputStream());
FileOutputStream fw =new FileOutputStream(writefile);
BufferedOutputStream bos = new BufferedOutputStream(fw);
int val = -1;
while((val=bis.read())!=-1){
bos.write(val);
}
bos.flush();
bos.close();
bis.close();
}
public static void main(String[] args) throws Exception {
Class c=Class.forName("DownLoad");
DownLoad d=(DownLoad) c.newInstance();
Object[] a=new Object[1];
Method m=c.getMethod("downLoad", null);
m.invoke(d, null);
// d.downLoad();
}
相关文章
- 暂无相关文章
用户点评