• 通过URl将服务器的图片下载到本地并压缩


    private void downloadServerPic(final String url1) {

        new Thread() {

                @Override  

                public void run() {

                    // 定义一个URL对象  

                    URL url;

                    try {  

                        url = new URL(url1); 

                        // 打开该URL的资源输入流  

                        InputStream is = url.openStream();  

                        is.close();  

                        // 再次打开RL对应的资源输入流  

                        is = url.openStream(); 

                        //创建输出流  

                FileOutputStream outStream = null;

                        try {

            byte[] bary = readInputStream(is);

            File imageFile = new File( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");  

            outStream = new FileOutputStream(imageFile);

                  //写入数据  

                  outStream.write(bary);  

            //getimage 方法见  http://www.cnblogs.com/wangzehuaw/p/4447120.html

                  bitMap = getimage( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");

                  //关闭输出流  

            } catch (Exception e) {

            e.printStackTrace();

            } finally {

              if(outStream != null) 

                outStream.close();

                is.close();  

            }

                      } catch (MalformedURLException e) {    

                            e.printStackTrace();  

                     } catch (IOException e) {  

                            e.printStackTrace();  

                      }  

      

                  }  

      

              }.start();  

        }

     

  • 相关阅读:
    bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊
    1691: [Usaco2007 Dec]挑剔的美食家
    CF809E Surprise me!
    「总结」狄利克雷卷积,莫比乌斯反演和杜教筛
    AT3611 Tree MST
    AT2134 Zigzag MST
    CF891C Envy
    【HNOI2018】游戏
    【HNOI2016】树
    【HNOI2016】网络
  • 原文地址:https://www.cnblogs.com/wangzehuaw/p/4487232.html
Copyright © 2020-2023  润新知