我想通过 ZipFile 类来读取一个ZIP 但是试了几种方法都不能够进行读取,所以想提出来想问问大家错在哪里?public class formatTest{
public static void main(String[] args)throws IOException{
ZipFile zf = new ZipFile("D:\\333\\111.zip");
ZipEntry ze2;
Enumeration e = zf.entries();
while(e.hasMoreElements()){
ze2 = (ZipEntry)e.nextElement();
System.out.println("File: " + ze2);
// CheckedInputStream cis = new CheckedInputStream(zf.getInputStream(ze2), new CRC32()); //注释的3句代码都是另一种读取
// ZipInputStream zis = new ZipInputStream(cis);
// BufferedInputStream bis = new BufferedInputStream(zis);
BufferedReader bis = new BufferedReader(new InputStreamReader(zf.getInputStream(ze2)));
int i;
while((i = bis.read()) != -1){
System.out.write(i);
}
}
}
}
public static void main(String[] args)throws IOException{
ZipFile zf = new ZipFile("D:\\333\\111.zip");
ZipEntry ze2;
Enumeration e = zf.entries();
while(e.hasMoreElements()){
ze2 = (ZipEntry)e.nextElement();
System.out.println("File: " + ze2);
// CheckedInputStream cis = new CheckedInputStream(zf.getInputStream(ze2), new CRC32()); //注释的3句代码都是另一种读取
// ZipInputStream zis = new ZipInputStream(cis);
// BufferedInputStream bis = new BufferedInputStream(zis);
BufferedReader bis = new BufferedReader(new InputStreamReader(zf.getInputStream(ze2)));
int i;
while((i = bis.read()) != -1){
System.out.write(i);
}
}
}
}
个人认为你应该用字节流啊,而不应该用字符流啊!
http://topic.csdn.net/u/20080708/19/1ca6881f-1736-4f2f-8554-0a12853472ae.html
public static void main(String[] args)
{ ZipFile zf;
try
{
zf = new ZipFile("D:\\111.zip"); ZipEntry ze2;
Enumeration e = zf.entries(); while (e.hasMoreElements())
{
ze2 = (ZipEntry) e.nextElement();
System.out.println("File: " + ze2);
BufferedReader bis; bis = new BufferedReader(new InputStreamReader(
zf.getInputStream(ze2)));
int i;
while ((i = bis.read()) != -1)
{
System.out.write(i);
} }
}
catch (Exception ex)
{
//to do yourself
} }