Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to delete all those text files (Notepad) that were created while Frame was running after closing the frame?

I want all text files (Notepad) created during run time to be deleted every time I close the program.

For example, while my program was running, files (ex. foods.txt, numbers.txt, and fruits.txt) were created, and I want those files to be deleted when I close or stop the program.

dont know if its possible to make

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This definitely is possible. You can do it in several ways:

  • While your program writes files, also add them to a list of files created by your application. On shutdown, iterate over this list and delete the files.

  • Or create a temp directory and all files inside of that. In the end, just delete that directory.

  • If you do not have a separate directory but at least can locate the file, remember the start time of the application. Upon closure traverse the filesystem to find files created after startup and delete those.

All in all you need to make up your mind how to detect the files to be deleted. I’d go for the temp directory.
How to create a temporary directory/folder in Java?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading