Hi all,

I'm sure this is a basic question, but i can't find any information on POI site 
about docx files other than that it supports and it's in early stages.

Does POI really supports ".docx" files, or it's better to work with the old 
".doc"?
I'm looking to do some replacing in word document files, and possible to add 
some additional data other than replacing.

I've tried to open a ".docx" file with the following code, but both throw an 
exception.
And can anyone send me a code example how to open a file.

InputStream a = new FileInputStream("c:\\teste.docx");
XWPFDocument doc = new XWPFDocument(a);

Exception in thread "main" 
org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the 
specified file: 'e:\temp\UserTemp\poifiles\poi-ooxml-996872636.tmp'
                at 
org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
                at 
org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
                at 
org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
                at org.apache.poi.util.PackageHelper.open(PackageHelper.java:53)
                at 
org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:98)
                at pt.link.poi.TestPoi.main(TestPoi.java:24)


XWPFDocument doc = new XWPFDocument(XWPFDocument.openPackage("c:\\teste.docx"));
Exception in thread "main" 
org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the 
specified file: 'c:\teste.docx'
                at 
org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
                at 
org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
                at 
org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
                at 
org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:62)
                at pt.link.poi.TestPoi.main(TestPoi.java:29)

Thanks
Pedro Pires

Reply via email to