aspose file tools*
The moose likes I/O and Streams and the fly likes Can i forcefully delete a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Can i forcefully delete a file" Watch "Can i forcefully delete a file" New topic
Author

Can i forcefully delete a file

adil qureshi
Ranch Hand

Joined: Jul 11, 2008
Posts: 48
Can i forcefully do a delete operation even if it is read/Write by someother stream .Actaully while deleting i dont know which all stream are linked to that file so can I get associated streams dynamically and close them all at once.


SCJP 1.5,SCWCD 1.5
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

>> Can i forcefully do a delete operation even if it is read/Write by someother stream

Through java .. I dont think you can do this. If the OS allows it.. then you can delete by executing OS command using Runtime.exec

>> Actaully while deleting i dont know which all stream are linked to that file so can I get associated streams dynamically and close them all at once

You can't get the associated streams dynamically.

BTW, Why do you want to delete a file which is being opened by somebody else ?


- Chinna
adil qureshi
Ranch Hand

Joined: Jul 11, 2008
Posts: 48
The problem i am facing is that the file is not getting deleted sometimes while sometimes it gets deleted ,many guys have taken a look through it but cant find an appropriate solution that why it doesn't gets deleted also please be assured that file is not opened elsewhere ...
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

There is an api which actually deletes the files while the virtual machine goes down..
Will that help you..

http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#deleteOnExit%28%29
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

adil qureshi wrote:The problem i am facing is that the file is not getting deleted sometimes while sometimes it gets deleted


If the file is not getting deleted, it may be happening that the filestream opened by someone.. is not closed properly

You should try to fix that problem first.
adil qureshi
Ranch Hand

Joined: Jul 11, 2008
Posts: 48
Thanks Dear....yeah i used a finally block to close the streams if they are not null ...and looks as if the bug is resolved..... thanks for your time....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i forcefully delete a file