I want to open read a workbook from a file and then safe it back to this file. Workbook wb = WorkbookFactory.create("file.xlsx"); FileOutputStream fileOut = new FileOutputStream("file.xlsx"); wb.write(fileOut); fileOut.close(); throws: Exception in thread "main" org.apache.poi.POIXMLException: java.io.IOException: Can't obtain the input stream from /docProps/app.xml at org.apache.poi.POIXMLDocument.getProperties(POIXMLDocument.java:141) at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:177) at line wb.write(fileOut) Caused by: java.io.IOException: Can't obtain the input stream from /docProps/app.xml at org.apache.poi.openxml4j.opc.PackagePart.getInputStream(PackagePart.java:500) at org.apache.poi.POIXMLProperties.<init>(POIXMLProperties.java:75) at org.apache.poi.POIXMLDocument.getProperties(POIXMLDocument.java:139) ... 2 more
Windows is fussy about reading and writing to the same file, so that might be it. Does it work if you save to a different file name? Does it work if you try it on linux?
Yes it works, if I take another filename. The program runs under windows, so i didn't try it on a linux system. Is using a different file for writing the recommended way? Then it should be descriped in the docs.
It's a standard restriction on windows, nothing POI specific. You'll either need to use a 2nd file, or close the original one before trying to write out to it. Or switch to an OS without the restrictions!
Shouldn't a Java program run on all OSs? Can you give me some example code for opening a workbook from an existing file and writing into to it on windows? Thanks!
Well written Java programs can run anywhere, but there remain a few platform specific ways you can shoot yourself in the foot... On Windows, you either need to full close the input stream *before* trying to open it again for writing, or you need to write to another file.
Thanks. Got it working. An example for Windows in your HOWTO could be helpful.
Send in the text and we'll add it!