简体   繁体   中英

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM