你可以自己加一个遍历去取子目录里所需的内容即袭枣可
请用org.apache.tools.zip下的包,不要则孝用java.util.zip下的包,因为中文支持不好
import java.io.IOException
import java.io.InputStream
import java.util.Enumeration
import org.apache.tools.zip.ZipEntry
import org.apache.tools.zip.ZipFile
public class TestZip {
public static void printZipTxt(String zipPath) throws IOException{
ZipFile zipFile=new ZipFile(zipPath)
for (Enumeration<? extends ZipEntry>e = zipFile.getEntries()e.hasMoreElements()){
ZipEntry entry=e.nextElement()
System.out.println("文孙禅稿件名:"+entry.getName()+", 内容如下:")
if(entry.getName().toLowerCase().endsWith(".txt")){
InputStream is=null
is= zipFile.getInputStream(entry)
byte[] b=new byte[1024]
int leng=-1
String txtStr=""
while (( leng=is.read(b)) !=-1){
txtStr+=new String(b, 0, leng)
}
System.out.println(txtStr)
if(is!=null){
is.close()
}
}
}
}
public static void main(String[] args) {
try {
printZipTxt("c:\\test.zip")
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)