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).]
But my issue is... File f = new File("a.txt"); FileOutputStream fos = new FileOutputStream(f); f.delete();
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.
Joined: Aug 30, 2000
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