ODT output file issue

27 views
Skip to first unread message

wael Hasrouni

unread,
Jan 23, 2013, 9:09:50 AM1/23/13
to jodrepor...@googlegroups.com
Hi,

I was able to create an output report based on ODT template but i m not able to delete this report after generating it.

The used code to generate the ODT report:

DocumentTemplateFactory documentTemplateFactory = new DocumentTemplateFactory();
DocumentTemplate template = documentTemplateFactory.getTemplate(new File("template.odt"));
Map<String, Object> data = new HashMap<String, Object>();
data.put("project", "project");

template.createDocument(data, new FileOutputStream("output.odt"));

now when the report has been successfully generated. I want to delete it on a certain action as follows:

File reportFile = new File("output.odt"");
if(reportFile.delete())
{
     System.out.println("report file deleted");
}
else
{
System.out.println("report file can not be deleted");
}

I m getting the "report file can not be deleted"

When i m trying to delete it manually it gives "File can not be deleted it is open in Java(TM) Platform SE binary".

I tried some work arounds  as the below but i m still can't delete the file:

OutputStream reportODT = new FileOutputStream("output.odt");
template.createDocument(data, reportODT);
reportODT.flush();
reportODT.close();

any ideas regarding this issue?

Regards,


Reply all
Reply to author
Forward
0 new messages