运用广播机制来完成版本更新模块(详解)
先看下主配置文件:
再看下主控制类:
下面来看下后台服务下载的代码:package com.xiaoma.utils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; /** * @Title: DeleteFile.java * @Description: 文件、文件夹操作类 * @author MZH */ public class FileUtils{ private URL url = null ; public FileUtils(){ } public File writeInput(String PathName, InputStream input){ File file = null; OutputStream output = null; try{ file = new File( PathName ); if (file.exists()) return file; int length = 0; output = new FileOutputStream(file); byte buffer[] = new byte[1024]; while((length = input.read(buffer)) > 0){ output.write(buffer, 0, length); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ output.close(); }catch(Exception e){ e.printStackTrace(); } } return file; } public InputStream getStreamFromUrl(String urlStr) throws MalformedURLException, IOException { url = new URL(urlStr); HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); InputStream inputStream = urlConn.getInputStream(); return inputStream; } }