unable to delete file

Hi.... i am using the command below to delete the particular file..... the file exists at that place..... the problem is that the functioning of the command is errqtic....it s not functioning some time ....while at other times it works perfectly.....Cud u pls help me...Thanx

File f = new File("C:/file/i.csv");

f.delete();

[342 byte] By [abhi@javaa] at [2007-10-3 4:34:39]
# 1

> Hi.... i am using the command below to delete the

> particular file..... the file exists at that

> place..... the problem is that the functioning of the

> command is errqtic....it s not functioning some time

> ....while at other times it works perfectly.....Cud u

> pls help me...Thanx

>

> File f = new File("C:/file/i.csv");

> f.delete();

Does the file exist [ f.exists() ] ?

aniseeda at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 2
yes as i mentioned before the file does exists.... i ve even used the f.exists() function..... but still the functioning is erratic..
abhi@javaa at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 3
file permission perhaps?
gigsza at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 4
and is the file in use?
Arbiea at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 5

wats happening is that i am using clover to use read the file .... now wen the format of the file is correct ... ie as required by clover for execution then the functioning is alright..... but if the format is not correct then an exception is thrown.. and the next time it does not function correctly

abhi@javaa at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 6
i ve been using in.close and out.close functions to close the input and output stream
abhi@javaa at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 7
It is probably realted with File permission of the specified file.
samue-1a at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 8
> It is probably realted with File permission of the> specified file.I doubt it. It's related to the file being in use more likely.
cotton.ma at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 9
I've had similar problem of not being able to delete the file only sometimes. Forcing jvm to garbage collect by invoking System.gc() seems to do the trick (ie. solve the problem). Search the forum for it for more info.
_maxmkleea at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...
# 10

> wats happening is that i am using clover to use read

> the file .... now wen the format of the file is

> correct ... ie as required by clover for execution

> then the functioning is alright..... but if the

> format is not correct then an exception is thrown..

> and the next time it does not function correctly

This almost certainly means that you aren't closing the file when the exception is thrown. Put the close into a finally {} block.

ejpa at 2007-7-14 22:38:18 > top of Java-index,Java Essentials,Java Programming...