• 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

Reasons File.delete() won't work?

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to delete a file using File.delete(), but it keeps returning false. I've verified that path to the file is correct and that the permissions on the file allow deleting, but it still doesn't work. Any ideas? The routine follows.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you checked on permissions (write access) on directory where file resides?
Now I'll take a look at the code.
How was tempFile created in the first place?
-Barry
[ August 13, 2002: Message edited by: Barry Gaunt ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try:

If you get "reason unknown", check to see if you've opened any input or output streams to the file in question, and make sure that you close the streams properly before you try to delete the file.
[ August 13, 2002: Message edited by: Jim Yingst ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim, I once played around with File.createTempFile() and the deleteOnExit() method. At that time I could never get the file automatically deleted.
That was on NT or Windows 2000. Did you ever hear about any such problem?
-Barry
[ August 13, 2002: Message edited by: Barry Gaunt ]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry- sounds vaguely familiar... ah, here we are. Allegedly fixed now.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what I've discovered:
The file name is retrieved from a table when the user clicks on it. If a single or double-click is done, the row is selected and the file name is returned, but for some reason the file is not deleted.
A long click (not quite a second) on the file name both returns the correct name and allows the file to be deleted.
Very strange.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Figured it out. There's an actionListener attached to the table that's causing a problem.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic