我近期做的一个软件的更新功能 备份下 :-)
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();
}
本文介绍了一个软件更新功能的备份实现过程,通过HTTP连接下载远程ZIP文件,并根据文件类型将其解压到不同目录中,如.jar文件存放在lib目录下,.jasper文件存放在templet目录下,.doc文件存放在files目录下。

被折叠的 条评论
为什么被折叠?



