我正在尝试下载给定网址的多个图片。我有以下代码,我坚持。有人可以帮我将折旧的http转换为URL吗?
for (int i = 0; i < URLS.length; i++) {
try {
File firstFile = new File(directory + "/" + i + ".png");
if (firstFile.exists()==false)
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(URLS[i]);
HttpResponse resp = httpClient.execute(httpGet);
if(resp.getStatusLine().getStatusCode()==200){
HttpEntity entity = resp.getEntity();
InputStream is = entity.getContent();
Boolean status = firstFile.createNewFile();
FileOutputStream fouts = new FileOutputStream(firstFile);
byte[] buffer = new byte[1024];
long total = 0 ;
int count;
while ((count = is.read(buffer))!=-1){
total+=count;
fouts.write(buffer,0,count);
}
fouts.close();
is.close();
publishProgress(i);
}
}
}
catch(MalformedURLException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
return null;
}
protected void onProgressUpdate(Object... values){
super.onProgressUpdate(values);
}
}
}