解压缩很简单啊
    public static void extractFile(String fileName, String outDir) throws IOException {
        try {
            BufferedOutputStream dest = null;
            BufferedInputStream is = null;
            ZipEntry entry;
            ZipFile zipfile = new ZipFile(fileName);
            Enumeration e = zipfile.entries();
            
            if (outDir == null || outDir.equals("")) {
                int k = fileName.lastIndexOf(FILE_SEPARATOR);
                if (k >= 0) {
                    outDir = fileName.substring(0, k);
                }
            }
            File outFile = new File(outDir);
            outFile.mkdir();
            while (e.hasMoreElements()) {
                entry = (ZipEntry) e.nextElement();
                String tempFileName = outDir + System.getProperty("file.separator")+ entry.getName();
System.out.println(tempFileName);
                File tempFile = new File(tempFileName);
                if (entry.isDirectory()) {
                    tempFile.mkdir();
                    continue;
                } else {
                    File aa = new File(tempFile.getParent());
                    aa.mkdir();
                }
                is = new BufferedInputStream(zipfile.getInputStream(entry));
                int count;
                byte data[] = new byte[BUFFER];
                FileOutputStream fos = new FileOutputStream(tempFile);
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = is.read(data, 0, BUFFER)) != -1) {
                    dest.write(data, 0, count);
                }
                dest.flush();
                dest.close();
            }
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

解决方案 »

  1.   

    多谢老兄了,我刚学JAVA,能不能帮忙加点注释啊,越详细越好的,呵呵
      

  2.   

    关键问题是我这里不太会处理:
    我本来读文件的代码:
    URL[] urls = new URL[3];
    urls[0] = new URL(getCodeBase(),"a.txt");
    urls[1] = new URL(getCodeBase(),"b.txt");
    urls[2] = new URL(getCodeBase(),"c.txt");
    for(int i=0;i<urls.length;i++){
        readLine(urls[i])//调用读文件的方法
    }public void readLine(URL url){
      DataInputStream in;
      try{
        in = new DataInputStream(url.openStream());
      }catch(Exception e){
        e.printStackTrace();
        //然后用in.readLine()得到我想要的数据,再将数据存入内存变量中去;
        
      }
    }
    请教:如果我开始将0.txt,1.txt,2.txt压缩成一个压缩文件,如zip.xy;那么我在这里读文件的时候该如何处理了?
    谢谢了!
      

  3.   

    在本地压缩和在本地解压缩的我已经做好了.
    但是现在我把它应用在网络上不会处理了.
    Enumeration entries;
    ZipFile zipFile;    try {
          zipFile = new ZipFile("????");//我的这个压缩文件是网络服务器上的,这里怎么弄?
          entries = zipFile.entries();
          while(entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry)entries.nextElement();
            zipFile.getInputStream(entry)
      

  4.   

    zipFile也是一个文件呀,你就按你原来对文件的方式从网上把这个文件先读出来放在本地(其实可以是任何你想放的地方),在用本地处理就行啦!
      

  5.   

    难道这个问题不能直接用从服务上获得的一个URL,然后再由URL获得一个输入流来处理的吗?