Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can i forcefully delete a file

 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> 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 ?

 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic