• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic