469,352 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Java code to delete a file is not working

38
Code to delete the file is given below:

File file = new File(filePath);
file.delete();

But this code does not delete the file.
Please post your thoughts on this issue.

Regards,
Ganesh
Dec 17 '07 #1
6 20213
JosAH
11,448 Expert 8TB
What does the method return?

kind regards,

Jos
Dec 17 '07 #2
ganeshp
38
What does the method return?

kind regards,

Jos
I have not checked its return value.
Dec 17 '07 #3
ganeshp
38
What is it returns false , even if the file exists.

My application generates many intermediate files , i want to delete them as and when i complete using them.

Please post ways to delete a file.
Please let me know your thoughts on this.

Regards,
Ganesh
Dec 17 '07 #4
BigDaddyLH
1,216 Expert 1GB
I have not checked its return value.
Oh. I'm curious why you haven't, since you are having trouble deleting.

Another method that may be useful to you is File's deleteOnExit() method. This method is handy for temporary files, but read its documentation.
Dec 17 '07 #5
The problem is probably because the file is open. If at some point in your program the file is opened, make sure its closed before deleting it.
eg:
FileInputStream in = new FileInputStream("c:/a.txt");
make sure you have
in.close();
before using delete.
Dec 30 '09 #6
pbrockway2
151 Expert 100+
@id62000
The problem was...

This thread is very, very old. Quietly sleeping. Possibly dead; certainly best left alone.
Dec 30 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Ravi | last post: by
4 posts views Thread by Michael K. | last post: by
2 posts views Thread by TOI DAY | last post: by
4 posts views Thread by Khan | last post: by
5 posts views Thread by wo20051223 | last post: by
4 posts views Thread by id10t error | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.