title: Open a File within an EJB
body: <p>I know that it is in general not allowed to access local Files (with java.io) within an EJB: nevertheless, I have an EJB which has to open an Excel File and edit it using the apache.poi library. If I do something like this:</p>
  
  <pre><code>@Stateless
  public class MyEJB {
  
  public void editExcel(){
  ...
  InputStream in =  MyEJB.class.getClassLoader().getResourceAsStream("/xls/ExcelFile.xls"); 
  
  final Workbook generatedExcel = new XLSTransformer().transformXLS(in, beans);
  ...
  
  } }
  </code></pre>
  
  <p>The filesystem structure:</p>
  
  <pre><code>MyEar.ear
  --my-ejb.jar
  ---com
  -----company
  -------ejbs
  ----------MyEJB.class
  ---xls
  -----ExcelFile.xls
  </code></pre>
  
  <p>In this case I will get an Instance of ZipFile$ZipFileInputStream (private inner class of ZipFileInputStream) and XLSTransformer will throw an IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream"), as it expects an InputStream representing ExcelFile.xls and gets instead a stream representing the whole my-ejb.jar.</p>
  
  <p>My questions: do you know how to solve this situation? What is the best practice for accessing file within EJBs?</p>
  
  <p>Thanks a lot!</p>