欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ZIP文件解压缩

程序员文章站 2022-05-15 10:59:01
...
	public void unZip(File file, String unzipFolder) throws IOException {

		byte b[] = new byte[2048];
		int length;

		ZipFile zipFile = new ZipFile(file, "MS932");
		@SuppressWarnings("rawtypes")
		Enumeration enumeration = zipFile.getEntries();
		ZipEntry zipEntry = null;
		OutputStream outputStream = null;
		InputStream inputStream = null;

		while (enumeration.hasMoreElements()) {
			zipEntry = (ZipEntry) enumeration.nextElement();
			File loadFile = new File(unzipFolder + zipEntry.getName());

			if (zipEntry.isDirectory()) {
				loadFile.mkdirs();
			} else {
				if (!loadFile.getParentFile().exists())
					loadFile.getParentFile().mkdirs();

				outputStream = new FileOutputStream(loadFile);
				inputStream = zipFile.getInputStream(zipEntry);

				/* 写入文件 */
				while ((length = inputStream.read(b)) > 0) {
					outputStream.write(b, 0, length);
				}
			}
		}
		outputStream.close();
		inputStream.close();
		zipFile.close();
	 }