The server image downloaded to the local and compressed by URl

private void downloadServerPic(final String url1) {

    new Thread() {

            @Override  

            public void run() {

                // define a URL object  

                URL url;

                try {  

                    url = new URL(url1); 

                    // Open the resource input stream of the URL  

                    InputStream is = url.openStream();  

                    is.close();  

                    // Open RL corresponding resource input stream again  

                    is = url.openStream(); 

                    // Create output stream  

            FileOutputStream outStream = null;

                    try {

        byte[] bary = readInputStream(is);

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

        outStream = new FileOutputStream(imageFile);

              //data input  

              outStream.write(bary);  

        // getImage  method, see http://www.cnblogs.com/wangzehuaw/p/4447120.html

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

              // close the output stream  

        } catch (Exception e) {

        e.printStackTrace ();

        } finally {

          if(outStream != null) 

            outStream.close();

            is.close();  

        }

                  } catch (MalformedURLException e) {    

                        e.printStackTrace ();  

                 } catch (IOException e) {  

                        e.printStackTrace ();  

                  }  

  

              }  

  

          }.start();  

    }

 

Reproduced in: https: //www.cnblogs.com/wangzehuaw/p/4487232.html

Guess you like

Origin blog.csdn.net/weixin_34233679/article/details/93778455