title: Apache POI - How to write XSSFWorkbook to POIFSFileSystem?
body: <p>Using Apache POI HSSF, we can create xls file like this  </p>
  
  <pre><code>private void write(HSSFWorkbook workbook) {
      POIFSFileSystem filesystem = new POIFSFileSystem();
      filesystem.createDocument(new ByteArrayInputStream(workbook.getBytes()), 
                      "Workbook");
      FileOutputStream stream = new FileOutputStream("test.xls");
      filesystem.writeFilesystem(stream);
  }
  </code></pre>
  
  <p>Similarly, how can I write with <code>XSSFWorkbook</code>? This does not have the <code>getBytes()</code> method.<br>
  I tried to create <code>ByteArrayInputStream</code> from <code>XSSFWorkbook</code> like this - </p>
  
  <pre><code>ByteArrayOutputStream baos = new ByteArrayOutputStream();
  workbook.write(baos); //XSSFWorkbook here
  ByteArrayInputStream bias = new ByteArrayInputStream(baos.toByteArray());
  </code></pre>
  
  <p>But the xlsx file created was corrupt. How can I write the workbook to disc using <code>POIFSFileSystem</code>?</p>
  
  <p>The same <code>XSSFWorkbook</code> was written sucessfully when I did like this - </p>
  
  <pre><code>FileOutputStream stream = new FileOutputStream("test.xlsx");
  workbook.write(stream);
  </code></pre>
  
  <p>When I extracted and compared the xlsx files, there was no difference. However, when I do a plain text compare on the xlsx files directly (without extracting), there are few differences in the bytes.</p>
  
  <p>So the problem should be in the <code>createDocument()</code> and/or <code>writeFilesystem()</code> methods of <code>POIFSFileSystem</code>. Can someone let me know how to write <code>XSSFWorkbook</code> using <code>POIFSFileSystem</code>?</p>