• Post Reply Bookmark Topic Watch Topic
  • New Topic

About deleting files using listFiles()  RSS feed

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is anybody there to help me?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()" ?
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the return value of the delete method?

Does the user account running this code have permission to delete the file?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


And check the File Permissions

HTH [I'm little bit late in reply, Ulf already explained ]
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!