public String readZipFile(String file) throws Exception {
ZipFile zipFile = null;
ZipInputStream zin = null;
InputStream in = null;
StringBuffer sbf = null;
try {
zipFile = new ZipFile(file);
in = new BufferedInputStream(new FileInputStream(file));
zin = new ZipInputStream(in);
ZipEntry ze;
sbf = new StringBuffer();
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
} else {
StringBuffer sBuffer = new StringBuffer();
// 这里的判断不能用ze.getSize() > 0, 当文件的大小很小时,会返回-1
if (ze.getSize() != 0) {
BufferedReader br = new BufferedReader(
new InputStreamReader(
zipFile.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
sBuffer.append(line + "\r\n");
}
sbf.append(sBuffer);
br.close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(in != null) {
in.close();
}
if(zin != null) {
zin.close();
}
if(zipFile != null) {
zipFile.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return sbf.toString();
}
ZipFile zipFile = null;
ZipInputStream zin = null;
InputStream in = null;
StringBuffer sbf = null;
try {
zipFile = new ZipFile(file);
in = new BufferedInputStream(new FileInputStream(file));
zin = new ZipInputStream(in);
ZipEntry ze;
sbf = new StringBuffer();
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
} else {
StringBuffer sBuffer = new StringBuffer();
// 这里的判断不能用ze.getSize() > 0, 当文件的大小很小时,会返回-1
if (ze.getSize() != 0) {
BufferedReader br = new BufferedReader(
new InputStreamReader(
zipFile.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
sBuffer.append(line + "\r\n");
}
sbf.append(sBuffer);
br.close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(in != null) {
in.close();
}
if(zin != null) {
zin.close();
}
if(zipFile != null) {
zipFile.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return sbf.toString();
}