论坛首页 Java企业应用论坛

如何保存一个ZipInputStream的副本?

浏览 2521 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-10-30  
OO
java 代码
  1. package ziptest;   
  2.   
  3. import java.io.FileInputStream;   
  4. import java.io.FileNotFoundException;   
  5. import java.io.IOException;   
  6. import java.io.InputStream;   
  7. import java.util.zip.ZipEntry;   
  8. import java.util.zip.ZipInputStream;   
  9.   
  10. /**  
  11.  * @version 2007-10-30  
  12.  * @author: Calvin Lee  
  13.  */  
  14. public class ZipTest {   
  15.     public static void main(String[] args) {   
  16.   
  17.         try {   
  18.             ZipInputStream zin = new ZipInputStream(new FileInputStream(   
  19.                     "d:/websale_rfid.zip"));   
  20.             FileInputStream filein = new FileInputStream("d:/websale_rfid.zip");   
  21.                         ZipInputStream zin2 = new ZipInputStream(zin);   
  22.                
  23.             ZipEntry entry;   
  24.             try {   
  25.                 while ((entry = zin.getNextEntry()) != null) {   
  26.                     System.out.println("++++++++++++++++" + (entry.getName()));   
  27.                     zin.closeEntry();   
  28.                 }  

 

  1.                 //zin2没能够正确形成   
  2.                 while ((entry = zin2.getNextEntry()) != null) {   
  3.                     System.out.println("~~~~~~~~~~~~~~~~~~" + (entry.getName()));   
  4.                     zin2.closeEntry();   
  5.                 }   
  6.   
  7.             } catch (IOException e) {   
  8.                 e.printStackTrace();   
  9.             }   
  10.         } catch (FileNotFoundException e) {   
  11.             e.printStackTrace();   
  12.         }   
  13.   
  14.     }   
  15.   
  16.       

输出为

++++++++++++++++forms.xml
++++++++++++++++gpd.xml
++++++++++++++++processdefinition.xml
++++++++++++++++processimage.jpg

而~~~~并没有输出

ZipInputStream zin2 = new ZipInputStream(zin); 为什么代码中zin2没能正确获得...???

如果我想重新读取一次zip流该怎么实现呢?------------------先不要告诉我根据FileInputStream再生成一次.......

直接根据原来的zip流不可以吗?

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics