我用的是jdk1.5,在jdk目录里有个src.zip,里面是jdk的类库。
可是当我用Eclipse打开里面的.java文件后,我发现里面很多地方用了如下的语法:
public Enumeration<? extends ZipEntry> entries() {
return new Enumeration<ZipEntry>() {.......
......................
...................对于以上语法,Eclipse直接提示“错误的标记”。  这是什么语法?有什么用?还有一个问题就是在java.util.zip 包中,Adlert32和CRC32这两个数据效验类都在哪种情况下使用?怎么用? CheckedOutputStream和CheckedInputStream这两个io流的效验和类又有什么用处?
望举实例说明其作用。

解决方案 »

  1.   

    //: c11:ZipCompress.java
    // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    // Uses Zip compression to compress any 
    // number of files given on the command line.
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;public class ZipCompress {
      // Throw exceptions to console:
      public static void main(String[] args) 
      throws IOException {
        FileOutputStream f =
          new FileOutputStream("test.zip");
        CheckedOutputStream csum =
          new CheckedOutputStream(
            f, new Adler32());
        ZipOutputStream out =
          new ZipOutputStream(
            new BufferedOutputStream(csum));
        out.setComment("A test of Java Zipping");
        // No corresponding getComment(), though.
        for(int i = 0; i < args.length; i++) {
          System.out.println(
            "Writing file " + args[i]);
          BufferedReader in =
            new BufferedReader(
              new FileReader(args[i]));
          out.putNextEntry(new ZipEntry(args[i]));
          int c;
          while((c = in.read()) != -1)
            out.write(c);
          in.close();
        }
        out.close();
        // Checksum valid only after the file
        // has been closed!
        System.out.println("Checksum: " +
          csum.getChecksum().getValue());
        // Now extract the files:
        System.out.println("Reading file");
        FileInputStream fi =
           new FileInputStream("test.zip");
        CheckedInputStream csumi =
          new CheckedInputStream(
            fi, new Adler32());
        ZipInputStream in2 =
          new ZipInputStream(
            new BufferedInputStream(csumi));
        ZipEntry ze;
        while((ze = in2.getNextEntry()) != null) {
          System.out.println("Reading file " + ze);
          int x;
          while((x = in2.read()) != -1)
            System.out.write(x);
        }
        System.out.println("Checksum: " +
          csumi.getChecksum().getValue());
        in2.close();
        // Alternative way to open and read
        // zip files:
        ZipFile zf = new ZipFile("test.zip");
        Enumeration e = zf.entries();
        while(e.hasMoreElements()) {
          ZipEntry ze2 = (ZipEntry)e.nextElement();
          System.out.println("File: " + ze2);
          // ... and extract the data as before
        }
      }
    }
      

  2.   

    以上是thinking in java中的源程序
      

  3.   

    对于Adler32刚又仔细试了一下,发现问题出在这里:
        ZipOutputStream out =
          new ZipOutputStream(
            new BufferedOutputStream(csum));
    如果,csum使用BufferedOutputStream装饰过,那么Adler32的效验和压缩前和解压缩后的就一样。
    如果没有使用BufferedOutputStream装饰,类似这样:
        ZipOutputStream out =
          new ZipOutputStream(csum);
    那么Adler32的效验和将会出错。 不知道是什么原因造成的
      

  4.   

    Eclipse 只有新版本才支持JDK 1.5的语法
      

  5.   

    这个东西就是相当于C++的模板(template)的东东了。
      

  6.   

    我的Eclipse已经是比较新的版本的了3.0.1的. 为什么还是不支持这种语法?
      

  7.   

    现在最新的eclipse支持JDK5了,下载试试
      

  8.   

    我的Eclipse已经是3.0.2的了。 从www.eclipse.org下载的最新的。
    为啥还是不行??
      

  9.   

    3.1才支持,不过3.1还没有还没有正式版本,最新的是3.1M6,我试过,好像还有不少Bug :(
    不过基本上还是可以用的。
      

  10.   

    eclipse 3.0.2还是支持jdk1.4,带M的才是支持jdk1.5的
      

  11.   

    eclipse3.1m4以上开始支持jdk1.5
    不是带m就支持,呵呵