• 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

File does not delete fast enough

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an app that listens for a certain file. The file is a JPEG that is about 669 KB in size. Once it finds it, it loads it. The app also deletes the file then listens for a new file with the same name to appear. The problem is that I cannot get the file deleted fast enough before the app wants to load it again. I have tried to put the deletion in a loop but it gets stuck there. Example:
while(!someFile.delete())
{
try
{
Thread.sleep(100);
}
catch(IOException ioe)
{
}
}
Any help will be greatly appreciated.
Warren Bell
Netricks
warren@netricks.net
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the checking of the file and displaying of the file should be in two separate threads. Use of wait/notify in these threads would allow them to communicate with each other.
For example:
while(!somefile.delete()) {
wait();
}
Your other thread would fire a notify() when it is done displaying the image.
Hope this helps.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double check your code to make sure that the file you are trying to delete was closed. If it is still open, the delete will not occur.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like to use a method like this when I delete files - if there's a problem, the IOException makes it obvious, and may succeed in identifying the cause:

However the most common problem appears as "reason unknown" using this method. It's the one Lu suggests - some other stream, channel, or RandomAccessFile is still open for this file, and needs to be closed. In many cases garbage collection will take care of this for you, but often it's not as quick as you might like. So be usre to close streams, channels, and RandomAccessFiles as soon as you're done with them. Don't wait for GC.
 
Warren Bell
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the suggestions, they really have helped.
Warren Bell
Netricks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic