Reputation: 25
I have spring mvc application and I need to return a preparated file to user as response on his request. The flow:
My solution: I have base zip file on my server, when user make a request, I'm copy base file to tmp file -> I unzip tmp file -> make modification -> zip it again -> returning to the user.
Problem: How to sure that tmp file will be deleted after I process the request (even if error happen in VM)?
There are many users at the same time.
The size of zip is more than 100M.
Upvotes: 0
Views: 283
Reputation: 681
https://howtodoinjava.com/java/io/how-to-delete-temporary-file-in-java/
here you have a good tutorial. Make sure that you call
File.deleteOnExit();
Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates
See https://docs.oracle.com/javase/8/docs/api/java/io/File.html#deleteOnExit--
Upvotes: 1