Page 1 of 1

FileNotFoundException while overwriting a file

PostPosted: Tue Jul 20, 2010 12:27 am
by horstdieter2
Hi,

if i try to save a generated document which was already opened, i get a FileNotFoundException. I can't catch the exception.

errorlog:

JAXB: Using Java 6 implementation.
java.io.FileNotFoundException: C:\test.docx (The process can not access the file because it is being used by another process)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:92)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:198)

Re: FileNotFoundException while overwriting a file

PostPosted: Thu Jul 22, 2010 9:51 pm
by horstdieter2
Hi jason,

the problem is located in the openpackaging.io.SaveToZipFile class.

example:

/* Save a Package as a Zip file in the file system */
82 public boolean save(String filepath) throws Docx4JException {
83 log.info("Saving to" + filepath );
84 try {
85 if (filepath.toLowerCase().endsWith(".xml") ) {
86 return saveFlatOPC(new FileOutputStream(filepath));
87 } else return save(new FileOutputStream(filepath));
88 } catch (FileNotFoundException e) {
89 // TODO Auto-generated catch block
90 e.printStackTrace();

91 return false;
92 }
93 }

Why not throw this FileNotFoundException or create a new Docx4JException ?

Re: FileNotFoundException while overwriting a file

PostPosted: Fri Jul 23, 2010 4:14 am
by jason
Hi, That's right, we should be doing something like that.

FileNotFoundException seems ok, provided we document that it can be thrown for the reason you have identified.

I'll do this over the next day or so.

cheers .. Jason