0

我想从服务器中提取并保存传入的 ZipFile。

这段代码只有一半的时间有效。

InputStream is = socket.getInputStream();
zipStream = new ZipInputStream(new BufferedInputStream(is);

ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
        String mapPaths = MAPFOLDER + entry.getName();
        Path path = Paths.get(mapPaths);
        if (Files.notExists(path)) {
            fileCreated = (new File(mapPaths)).mkdirs();
        }

        String outpath = mapPaths + "/" + entry.getName();
        FileOutputStream output = null;
        try {
            output = new FileOutputStream(outpath);
            int len = 0;
            while ((len = zipStream.read(buffer)) > 0) {
                output.write(buffer, 0, len);
            }
        } finally {
            if (output != null)
                output.close();
        }
    }

我认为问题是,方法 zipStream.getNextEntry() 在数据传入之前被调用,我如何等待传入数据读取?

4

0 回答 0