我近期做的一个软件的更新功能 备份下 :-)
URL url = new URL(path+"/test.zip"); HttpURLConnection httpConnection = (HttpURLConnection) url. openConnection(); int responseCode = httpConnection.getResponseCode(); if (responseCode == 200) { ZipInputStream zis = new ZipInputStream(httpConnection. getInputStream()); ZipEntry zen = zis.getNextEntry(); FileOutputStream out = null; byte[] c = new byte[1024]; int slen; while (zen != null) { if (!zen.isDirectory()) { if (zen.getName().endsWith(".jar")) { out = new FileOutputStream("./lib/" + zen.getName()); log.info("开始创建"+zen.getName()); } else if (zen.getName().endsWith(".jasper")) { out = new FileOutputStream("./templet/" + zen.getName()); log.info("开始创建"+zen.getName()); } else if (zen.getName().endsWith(".doc")) { File file = new File("./files"); if (!file.exists()) { file.mkdir(); } out = new FileOutputStream("./files/" + zen.getName()); log.info("开始创建"+zen.getName()); } while ((slen = zis.read(c, 0, c.length)) != -1) { out.write(c, 0, slen); } out.close(); } zen = zis.getNextEntry(); } zis.close(); }