471,572 Members | 880 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,572 software developers and data experts.

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
7 28089
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
AnnoyedAtYou
1 Bit
@pbrockway2

Certainly not best left alone. A late reply might not help the person that asked, but it doesn't mean it won't help anyone. So, get your head out of your a** and stop telling people off for being helpful.
Sep 20 '22 #8

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
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.