Home Ask Login Register

Developers Planet

Your answer is one click away!

Polyakoff February 2016

How to remove ICEpdf temporary files after application has finished working?

I use ICEpdf library for PDF displaying at my desktop java application. Application adds annotations to PDF at runtime, but without changing original files — changes are displayed only during one 'session'. I recently discovered that application creates a lot of temporary files which consume quite a lot of disk space.

Method org.icepdf.core.pobjects.Document.setInputStream has the following code:

// Delete temp file on exit 

So I suppose it has to remove temporary files after it used them, but it does not:

ICE pdf temporary files

How can I programmatically remove all files created by application on exit or make standard file removing work?


Slava Gornostal February 2016

To get temp folder path:


To remove files:

try (DirectoryStream<Path> paths = Files.newDirectoryStream(pathToDir, regex)){
        paths.forEach(path -> path.toFile().delete());
    } catch (IOException e) {
        // handle io exception

where regex is filename pattern. In your case: "IcePdf*"

Post Status

Asked in February 2016
Viewed 3,830 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life