`

java下载apk

 
阅读更多

         //url是apk存放的路径 ,由于项目需要,url是解析配置文件.xml,如下注释代码

//Document xml  = getXmlDoc(path);
 //Node node = xml.selectSingleNode("/update/application/url");
 //String url=node.getText(); 

 

 

 

 

         URL downUrl = new URL(url);
         URLConnection conn = downUrl.openConnection();
         InputStream is = conn.getInputStream();
         BufferedInputStream in = new BufferedInputStream(is);
         response.addHeader("Content-Disposition", "attachment;filename=" + "WisdomCommunity.apk");
          //response.setContentType("application/vnd.android.package-archive");
         response.addHeader("Content-Type", "application/vnd.android.package-archive");
         OutputStream outputStream = response.getOutputStream();
         byte[] data = new byte[1024];
         int size = 0;
         int l = 0;
         while ((l = in.read(data)) > 0) {
              size += l;
              outputStream.write(data, 0, l);
         }
         response.addHeader("Content-Length", size + "");
         outputStream.flush();
         outputStream.close();
         in.close();
         is.close();

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics