I have written a program which creates a MSaccess data base in a temp folder. I need to delete the Tempfolder after download is done at the client side.
@PostConstruct
public void init() {
try {
lb.createLbTable(readType());
Path path = Paths.get(lb.getTempFolder().toString(), "MyDB.accdb");
this.lbAll = new DefaultStreamedContent(Files.newInputStream(path), "accdb", "MyDB.accdb");
} catch (IOException e) {
LOGGER.error(e.getMessage(),e);
}
}
@PreDestroy
public void destroy() {
leistungsbereichAccess.deleteTempFolder();
}
And the delete Method from the other class:
public void deleteTempFolder() {
try {
FileUtils.forceDelete(tempFolder.toFile());
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
It only works if I use forceDeleteOnExit
which deletes only the current directory after killing the jbose server. But I need to delete the directory after the client is done with the download. At time I get 'Unable to delete file:..'
because it is locked by download manager.