Bug 60776 - Opening an excel workbook with WorkbookFactory twice results in IOException
Summary: Opening an excel workbook with WorkbookFactory twice results in IOException
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.15-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-27 07:47 UTC by Rob Gemen
Modified: 2017-02-27 09:13 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Gemen 2017-02-27 07:47:58 UTC
this is the code that fails:
    InputStream inputStream = null;
    inputStream = new FileInputStream(inputFile);
    Workbook workbook = WorkbookFactory.create(inputStream);
    Workbook workbook2 = WorkbookFactory.create(inputStream);

The inputFile is just a regular File that contains a valid xls file. No strange stuff.

The first creationof a workbook succeeds. Doing the same thing twice (creating workbook2) gives an IOException. No Idea why bu I guess this should be possible. Inputstream is still a valid Object and hasn't changed. So why isn't possible to create a second workbook object out of it?
Comment 1 Nick Burch 2017-02-27 09:13:59 UTC
InputStreams are generally read-once

See also http://poi.apache.org/spreadsheet/quick-guide.html#FileInputStream - if you have a File you should be using that to read from!