当前位置:首页
开发技术指南» 文章正文
    引言:

    摘要: 小弟最近要搞webservice,以前从来没有接触过,请问各位大虾,学习webservice,需要一个什么样的步骤呢?比如应该先看看什么书,资料呢?好入个门 ......
 ·小弟问一个很菜的问题    »显示摘要«
    摘要: 有这么一段程序: public void page_load(object sender, eventargs e) { ...... button1.click += new eventhandler(this.button1_click); } public void button1_click(object sender, eventargs e) { label1.text = &......


问关于ZipOutputStream

最近写了个小程序,把jar包解压缩后,修改里面的一个配置文件,然后再重新压缩。结果运行该jar包中的程序时,报找不到指定的类。我对比了一下重新压缩后的jar包里的每个类文件比原压缩包中小了一些。其他没发现什么异常,不知是什么原因重新压缩后会找不到类。  
        我的压缩文件的部分程序如下:  
  static   final   int   BUFFER=2048;  
  //filelist:     要压缩的文件列表  
  //filename:     压缩后文件名  
  public   static   boolean   Compressfile(String[]   filelist,String   filename){  
   
   
  try   {  
   
   
  // 创建ZipOutputStream对象,将向它传递希望写入文件的输出流  
  File   zipFile=new   File(filename);  
  FileOutputStream   fos=new   FileOutputStream(zipFile);  
  ZipOutputStream   zout=new   ZipOutputStream(new   BufferedOutputStream(fos,BUFFER));  
   
   
   
   
  for(int   i=0;i<filelist.length;i++)  
  //调用compress压缩文件  
  if(!(compress(filelist[i],zout))){  
  System.out.println("failed   compress   the   file"+filelist[i]);  
  zout.close();  
  return   false;  
   
  }  
   
     
   
  zout.close();  
  return   true;  
  }   catch   (FileNotFoundException   e)   {  
  //   TODO   Auto-generated   catch   block  
  e.printStackTrace();  
  return   false;  
  }   catch   (IOException   e)   {  
  //   TODO   Auto-generated   catch   block  
  e.printStackTrace();  
  return   false;  
  }  
   
   
   
   
   
   
  }  
   
   
   
  private   static   boolean   compress(String   filename,ZipOutputStream   zout){  
   
  File   file=new   File(filename);  
  byte[]   buf=new   byte[BUFFER];  
   
  try   {  
   
  if(file.isDirectory()){  
   
  ZipEntry   ze=new   ZipEntry(filename+"\\");  
  zout.putNextEntry(ze);  
  zout.closeEntry();  
  String[]   fl=file.list();  
  for(int   i=0;i<fl.length;i++){  
        StringBuffer   sb=new   StringBuffer(fl[i]);  
          sb.insert(0,filename+"\\");  
                  fl[i]=sb.toString();  
  compress(fl[i],zout);  
  }  
   
  }else{  
   
  FileInputStream   fin=new   FileInputStream(filename);  
  BufferedInputStream   in=new   BufferedInputStream(fin);    
  ZipEntry   ze=new   ZipEntry(filename);  
  zout.putNextEntry(ze);  
   
   
   
   
  while   (true)    
  {  
  int   nRead   =   in.read(buf,   0,   buf.length);  
  if   (nRead   <=   0)  
  break;  
  zout.write(buf,   0,   nRead);  
   
  }  
   
  zout.closeEntry();  
  }  
   
  return   true;  
  }   catch   (IOException   e)   {  
  //   TODO   Auto-generated   catch   block  
  e.printStackTrace();  
  return   false;  
  }  
   
   
   
  }  
  请问问题出在哪里呢?是否往ZipOutputStream中写文件时有问题呢?会写完以后的文件大小变小。  
   
  哪位大侠帮忙指点一下,多谢了!

NO.1   作者: majy

有些out在关闭之前应该flush一下的,要不然可能不会把所有的memory内容都写都文件中


 ·怎么登陆sql*plus    »显示摘要«
    摘要: 输入用户名:system 口令;manager 主机名:my 之后提示:"监听进程不能解析在连接描述符中给出的servers_name" 为什么呀 怎么进入呀 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE