首页 文章

获取java.io.IOException:流关闭错误而不显式关闭它

提问于
浏览
-2

我写了第一个文件后,我的zipInputStream正在关闭,即使我没有关闭任何流 .

ZipInputStream zipInputStream = new ZipInputStream(inputStream); 
 ZipEntry zipEntry = zipInputStream.getNextEntry();
  while (zipEntry != null) {

        modelFolderName = <somefoldername>
        modelFileName = <somefilename>

        String FILE_STORAGE_LOCATION = env.getProperty("workspacePath");

        File folder = new File(FILE_STORAGE_LOCATION + "/" + modelFolderName );
        if(!folder.exists()) {
            folder.mkdirs();
        }

        try (FileOutputStream fout=new FileOutputStream(FILE_STORAGE_LOCATION + "/" +  modelFolderName + "/" + modelFileName)) {
            try (BufferedInputStream in = new BufferedInputStream(zipInputStream)) {
              byte[] buffer = new byte[8096];
              while (true) {
                int count = in.read(buffer);
                if (count == -1) {
                  break;
                }
                fout.write(buffer, 0, count);
              }
            }
        }
        zipEntry = zipInputStream.getNextEntry();
    }

1 回答

相关问题