title: Exception in thread "main" java.io.IOException: Stream Closed
body: <p>When i try to execute the below code from main method, i am getting Stream Closed error.But i haven't closed any stream in my code.i even tried to close the workbooks after the for loop but still got the same error. Can anyone help me in resolving this issue?</p>
  
  <pre><code>Code: 
  
  public class ExcelCompare
  {
      public void compare(String path1, String path2 ) throws IOException
      {
      FileInputStream fs = new FileInputStream(path1);
      XSSFWorkbook wk = new XSSFWorkbook(fs);
      XSSFSheet s = wk.getSheet("Sheet1");
      int rcount = s.getPhysicalNumberOfRows();
      FileInputStream fs1 = new FileInputStream(path2);
      XSSFWorkbook wk1 = new XSSFWorkbook(fs);
      XSSFSheet s1 = wk.getSheet("Sheet1");
      for(int i=1; i&lt;rcount; i++)
      {
          XSSFRow r = s.getRow(i);
          XSSFRow r1 = s1.getRow(i);
          int ccount = r.getPhysicalNumberOfCells();
          for(int j=0;j&lt;=ccount;j++)
          {
              XSSFCell c = r.getCell(j);
              XSSFCell c1 = r1.getCell(j);
              if(c.getCellType()==1)
              {
                  if((c.getStringCellValue()).equals(c1.getStringCellValue()))
                      {
  
                      }
              }
  
              else
              {
                  System.out.println("value mismatch"+ c.getStringCellValue() +c.getStringCellValue());
              }
          }
      }
  
      }
  
  }
  
  Error: 
  
  Exception in thread "main" java.io.IOException: Stream Closed
      at java.io.FileInputStream.readBytes(Native Method)
      at java.io.FileInputStream.read(FileInputStream.java:255)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
      at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
      at org.apache.poi.util.BoundedInputStream.read(BoundedInputStream.java:121)
      at org.apache.poi.util.BoundedInputStream.read(BoundedInputStream.java:103)
      at org.apache.poi.util.IOUtils.copy(IOUtils.java:312)
      at org.apache.poi.util.IOUtils.peekFirstNBytes(IOUtils.java:70)
      at org.apache.poi.util.IOUtils.peekFirst8Bytes(IOUtils.java:57)
      at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:135)
      at org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:175)
      at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:209)
      at org.apache.poi.openxml4j.opc.ZipPackage.&lt;init&gt;(ZipPackage.java:98)
      at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
      at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
      at org.apache.poi.xssf.usermodel.XSSFWorkbook.&lt;init&gt;(XSSFWorkbook.java:295)
      at excel.ExcelCompare.compare(ExcelCompare.java:21)
      at excel.ExcelExecute.main(ExcelExecute.java:13)
  </code></pre>