抓图片2_习惯累积沉淀_新浪博客

String picpath = "http://xxxDEN/00.jpg";
try {
URL url = new URL(picpath);
InputStream inputStream = url.openStream();
OutputStream outputStream = new FileOutputStream(new File("d:"+File.separator+"a.jpg"));

int temp=0;  
byte[] b = new byte[500];
       while((temp=inputStream.read(b))!=-1){  
           outputStream.write(b,0,temp);  
       }  
       outputStream.flush();
       inputStream.close();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
从流中得到图片. 弄个缓冲区读取写入. flush一下. 到手抓图片2

ok技术可行的. 开始完善.

public void downloadPic(String path, String locationpath){
String picpath = path;//"http://exxxxx00.jpg";
try {
URL url = new URL(picpath);
InputStream inputStream = url.openStream();
(new File("d:"+File.separator+"somepic"+File.separator+locationpath)).mkdirs();
OutputStream outputStream = new FileOutputStream(new File("d:"+File.separator+"somepic"+File.separator+locationpath+File.separator+count+".jpg"));
count ++;
int temp=0;  
byte[] b = new byte[500];
       while((temp=inputStream.read(b))!=-1){  
           outputStream.write(b,0,temp);  
       }  
       outputStream.flush();
       inputStream.close();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
定义一个用来计数的变量. 给不同的图片当文件名.
int count = 0;
public void getItAll(){
Content content = getContent();
for(String s : content.getPathArray()){
System.out.println(s);
downloadPic(s,content.getTitle());
}
count = 0;
}
OK了. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值