aspose file tools
The moose likes Java in General and the fly likes About deleting files using listFiles() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "About deleting files using listFiles()" Watch "About deleting files using listFiles()" New topic
Author

About deleting files using listFiles()

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hiall,

I have this peace of code for deleting files-






Basically what i want is to delete the previouslog file.
It's a tiny part of a class which is called at last to delete
the log file after taking backup.
I am using spring to load the context and all.

In this i am getting the location of log file to be deleted from log.properties file.

But i am not getting desired result. I mean the files are not
getting deleted. I think there is something wrong with calling listFiles().
Can you please point out where i am doing mistake?

Thanks.

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Is anybody there to help me?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

kayanaat sidiqui wrote: I think there is something wrong with calling listFiles().

can you print out the name of all the files, when you get file array from "listFiles()" ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
can you print out the name of all the files, when you get file array from "listFiles()" ?


ya i am getting right file names.

I put these lines-



It's giving exact path name and file name.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35432
    
    9
What's the return value of the delete method?

Does the user account running this code have permission to delete the file?


Android appsImageJ pluginsJava web charts
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1



And check the File Permissions

HTH [I'm little bit late in reply, Ulf already explained ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19230

Also, if there still is an input or output stream to the file open, you can't delete the file because it is still busy.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
I tried using -



It's returning false.

And yes Rob i think file is still in use because of context.
But in that case it should throw the exception. am i right?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35432
    
    9
But in that case it should throw the exception. am i right?

No. Making assumptions about which method might throw an exception in which situation is not a good basis for writing code; that's what the javadocs are for - they tell you when exceptions are thrown. In this case, you need to go by the return value of the method call.
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hi all,

I saw my code andcame to knowthat filethat iwant to delete is still in use.

But any how i want to delete that files.

So is there any way to delete files forcefully?
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hi all,

I saw my code andcame to knowthat filethat iwant to delete is still in use.

But any how i want to delete that files.

So is there any way to delete files forcefully?
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hi all,

Well i saw my code and came to know that file to which i want to delete,
is still in use.

Ok. But any howi want to delete these files.
So is there anyway to delete files forcefully?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

kayanaat sidiqui wrote:
Well i saw my code and came to know that file to which i want to delete,
is still in use.

Ok. But any howi want to delete these files.
So is there anyway to delete files forcefully?


Try closing file, and then delete
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: About deleting files using listFiles()
 
Similar Threads
files are not delete
File writing taking long time.
Writing logs to a single file from Multiple Classes
Lucene beginner question
FTPClient : is not working