解压缩文件夹

public static void main(String[] args) throws Exception {

		File file = new File("d:"+File.separator+"test.zip");
		File outFile = null;
		ZipFile  zipFile = new ZipFile(file);
		ZipInputStream zipInput = null;
		OutputStream out = null;
		InputStream input = null;
		ZipEntry entry=null;
		zipInput =new ZipInputStream(new FileInputStream(file));
		
		while((entry = zipInput.getNextEntry())!=null){
			System.out.println("解压缩"+entry.getName()+"文件.");
			outFile = new File("d:"+File.separator+entry.getName());
			if(!outFile.getParentFile().exists()){
				outFile.getParentFile().mkdir();
			}
			if(outFile.exists()){
				outFile.createNewFile();
			}
			input = zipFile.getInputStream(entry);
			out = new FileOutputStream(outFile);
			int temp=0;
			while((temp=input.read())!=-1){
				out.write(temp);
			}
			input.close();
			out.close();
		}
		input.close();
		
		
	}

你可能感兴趣的:(解压缩文件夹)