title: File locked for editing
body: <p>I am doing some code that writes an Excel file. However, when opening the file created at the end of the <code>main</code> function, Open Office displays an error message that the file is locked by an unknown user. I checked and it seems I am closing all the references to the file and the workbook using the file.</p>
  
  <p>Thanks in advance for any help!</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public class StandingsFile
  {
      private Workbook workbook;
  
      public StandingsFile(InputStream inputStream, File outputFile)
      {
          this.outputFile = outputFile;
          workbook = POIExcelFileProcessor.createWorkbook(inputStream);
      }
  
      public void write()
      {
          // Code where the sheets in the Excel file are modified
  
          POIExcelFileProcessor.writeWorkbook(workbook, outputFile);
      }
  
      public static void main(String[] args)
      {
          standingsExcelFile = new StandingsFile(StandingsCreationHelper.class.getResourceAsStream(TEMPLATE_FILENAME), outputFile);
          standingsExcelFile.write();
  
          try
          {
              Desktop dt = Desktop.getDesktop();
              dt.open(outputFile);
          }
          catch (Exception ex)
          {
              e.printStackTrace();
          }
      }
  }
  
  public class POIExcelFileProcessor
  {
  
      public static Workbook createWorkbook(InputStream inputStream)
      {
          Workbook workbook = null;
  
          try
          {
              workbook = WorkbookFactory.create(inputStream);
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
          return workbook;
      }
  
      public static void writeWorkbook(Workbook workbook, File outputFile)
      {
          try
          {
              FileOutputStream fileOut = new FileOutputStream(outputFile);
              workbook.write(fileOut);
  
              fileOut.flush();
              workbook.close();
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
      }
  </code></pre>