URL url = new URL("图片地址");
URLConnection uc = url.openConnection();
InputStream is = uc.getInputStream();
File file = new File("本地路径");
FileOutputStream out = new FileOutputStream(file);
int i=0;
while ((i=is.read())!=-1) {
out.write(i);
}
is.close();
URLConnection uc = url.openConnection();
InputStream is = uc.getInputStream();
File file = new File("本地路径");
FileOutputStream out = new FileOutputStream(file);
int i=0;
while ((i=is.read())!=-1) {
out.write(i);
}
is.close();
FileOutputStream fos = null;
BufferedInputStream bis = null;
HttpURLConnection httpUrl = null;
URL url = null;
String fullPath = null;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
try {
url = new URL(destUrl);
httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.connect();
bis = new BufferedInputStream(httpUrl.getInputStream());
fullPath = getFullPath(pathName,this.fileFormat);
fos = new FileOutputStream(fullPath); while ( (size = bis.read(buf)) != -1) {
fos.write(buf, 0, size);
}
fos.flush();
}
catch(IOException e) {
}
catch(ClassCastException e) {
}
finally {
try {
fos.close();
bis.close();
httpUrl.disconnect();
}
catch(IOException e) {
}
catch(NullPointerException e) {
}
}
return getImageName(fullPath);
}