This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Folks : I have this question. File.delete() , actually deletes the file object Is there a method to actually delete the created file from OS directory structure?
OR i am asking too much from java to do since it may violate the security features
Hi Ragu, The quickest way to find the answer is to check the JDK API Here's what is says for the delete() method in File. public boolean delete() Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted. Returns: true if and only if the file or directory is successfully deleted; false otherwise Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited July 20, 2001).]
I think this will be my new mantra: When in doubt, check the API. If you are still in doubt, check the source. If doubt still remains, ask at JavaRanch.
This f.delete() does remove the content of the file f. However it does not remove the file as such physically (ie a.txt) from the OS directory structure. Is there any issues you folks can think of ... that i need to check to make this happen? Please help..... Thankx :-)
Well i think that the file will be deleted from ur directory, after that b'coz if use boolean exists() method which particularly check that whether that file exists on ur system or not it returns false.
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
Ragu, File.delete() will remove the file from the directory. The problem is, you're calling FileOutputStream with the same File descriptor; which creates an empty file with the same name. To see the behaviour. Create a test file using notepad. Call File.delete() on the test file. Check your directory; the test file will be gone. Now add a FileOutputStream statement using the same File descriptor; you'll see it the file in your directory with 0 bytes. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform