Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Deleting a File

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends,

i am trying to delete a file in java . using delete function

in File class. After Deleting the file , the File is not shown in recycle

bin . then , where it is gone?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just guessing here, but maybe it's been... deleted? As if you've deleted a file and also emptied the trash. It's gone. Java doesn't necessarily know or care how to collaborate with the Windows garbage can. At least it doesn't under Windows 2000 PRo; I don't know about other systems. If you want to be able to recover a file later, don't delete it using Java's File class. You could move it to some other location using renameTo() if you prefer.

It's also possible that some other program like Norton SystemWorks might know how to recover the file if you really need to. However, it's not something supported by the standard Java libraries. Hope that helps...
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "Recycle Bin" is a Windows Explorer concept.
Trying deleting using the 'del' command at the command line - you won't see any Recycle Bins there either.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The File.delete() method uses the filesystem of the underlying OS to perform the delete function. If the Windows filesystem had been configured to send deleted files to the Recycle bin, that is what would happen.

Windows Explorer moves files to the recycle bin and the underlying delete function isn't called until the recycle bin is emptied.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
File.delete() in java permanently deletes the file instead of moving it to the recylce bin. And this behaviour is independent of the Windows settings to move the files to Recycle bin while deleting it.

But I think Java or may be SWT should provide some options to delete the file to recycle bin or may be this behaviour shoudl be dependent on the OS settings.

--Randhir
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic