• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Delete genterated Files

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 110
Firefox Browser MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic