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();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值