这个方法接收2个参数,例如一个网络上的图片,和你要保存图片的地址.
public boolean initPhoto(String photoUrl,String filePath) {
try {
URL url = null;
try {
url = new URL(photoUrl);
} catch(Exception e) {
System.out.println("URL ERROR");
return false;
}
FilterInputStream in=(FilterInputStream) url.openStream();
File fileOut=new File(filePath);
FileOutputStream out=new FileOutputStream(fileOut);
byte[] bytes=new byte[1024];
int c;
while((c=in.read(bytes))!=-1) {
out.write(bytes,0,c);
}
in.close();
out.close();
return true;
} catch(Exception e) {
System.out.println("Error!");
return false;
}
}
posted on 2006-08-07 11:00
我心依旧 阅读(3677)
评论(11) 编辑 收藏