zip格式转化成String

2019-04-16 14:30:47 浏览数 (1)

代码语言:javascript复制
</pre><pre name="code" class="java"><pre name="code" class="java"><pre name="code" class="java">public static StringBuffer readZipFile(File file) throws Exception {
		StringBuffer html = new StringBuffer();

		ZipFile zf = new ZipFile(file);
		Enumeration<? extends ZipEntry> zipEntry = zf.entries();
		ZipEntry ze;
		while (zipEntry.hasMoreElements()) {
			ze = zipEntry.nextElement();
			if (ze.isDirectory()) {
				
			} else {
				long size = ze.getSize();
				if (size > 0) {
					BufferedReader br = new BufferedReader(
							new InputStreamReader(zf.getInputStream(ze)));
					String line;
					while ((line = br.readLine()) != null) {
						html.append(line);
					}
					br.close();
				}
			}
		}
		return html;
	}
代码语言:javascript复制

0 人点赞