• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete genterated Files

 
T Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my servlet, I am creating files at runtime. These files are stored in the root directory of my servlet container.

I need to clean these files up at some time. I have created a thread to do this within my servlet.

However, I use the myfile.delete() method. The file is not deleted.
I tested the file object for canWrite()...returns false.

What is the best way (if at all) to delete these files?

thanks very much!

TRW
 
Venkata Kumar
Ranch Hand
Posts: 110
Firefox Browser Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may start a thread in init function of servlet to check and delete the files. Close the file stream properly after writing the content in file.
 
T Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but that did not work. I got the same error.

The logic is I read through the directory and create a file object
for any file that meets certain criteria for deletion.

I then call the delete() method of the file object which of course
fails to delete the file.

I can delete files from my servlet that are NOT in the container. I'm
assuming there is either a permission issue or tomcat won't allow it.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat does not normally lock files in any way.

I am betting that either some process still has those files open or this is a permission problem. How was Tomcat installed - service or user application?

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic