Java代码

String urlpath="http://i2.sinaimg.cn/dy/dsgb/20083.jpg";    try {URL url=new URL(urlpath);HttpURLConnection con = (HttpURLConnection) url.openConnection();con.setConnectTimeout(6000);con.setRequestMethod("GET");if(con.getResponseCode()==200){byte[] imagebytes = readStreamtoBytes(con.getInputStream());File file =new File("pic.jpg");FileOutputStream fos =new FileOutputStream(file);fos.write(imagebytes);fos.close();}

Java代码

public static byte[] readStreamtoBytes(InputStream instream) throws IOException{

ByteArrayOutputStream outstream =new ByteArrayOutputStream();

int len=-1;
byte[] b = new byte[1024];
while((len = instream.read(b)) != -1){

outstream.write(b, 0, len);
}
outstream.flush();
outstream.close();
instream.close();

return outstream.toByteArray();

}

更多相关文章

  1. Android之十三图片2D翻转
  2. android webview实现唤起qq临时会话
  3. 在Eclipse 中关联android sdk 源代码
  4. Android的Location功能代码
  5. recovery代码流程
  6. Android(安卓)Studio配置Android(安卓)annotation(注解)
  7. Android腾讯微薄客户端开发十四:首页menu菜单
  8. 操作内存卡的常用代码
  9. Android(安卓)Studio使用AIDL时无法找到自定义的类

随机推荐

  1. 在Windows7下构建Android的开发环境
  2. 【Android(安卓)应用开发】Activity 任务
  3. Android(安卓)configChanges属性总结
  4. SurfaceHolder.Callback
  5. android Installation error: INSTALL_FA
  6. Android图片圆角转换 RoundedImageView开
  7. Android总结篇系列:Android(安卓)Intent
  8. Android四大组建
  9. android:windowSoftInputMode属性的使用
  10. 在android framework中添加自定义系统服