zoukankan      html  css  js  c++  java
  • 通过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();  

        }

     

  • 相关阅读:
    Gym 102040B Counting Inversion(超级数位dp)
    Educational Codeforces Round 104 (Rated for Div. 2)(A~D)
    2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_组队训练
    线段树板子
    Codeforces Round #700 (Div. 2)
    Codeforces Round #699 (Div. 2)
    Codeforces Round #698 (Div. 2)
    字典树——实现字符串前缀查找(可返回字符串)
    LeetCode146-LRU缓存机制
    用到过的git命令
  • 原文地址:https://www.cnblogs.com/wangzehuaw/p/4487232.html
Copyright © 2011-2022 走看看