• Post Reply Bookmark Topic Watch Topic
  • New Topic

File which is open should not be deleted?

 
Meenal Srivastva
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i ensure in my code that a file which is open should not be deleted?
I had expected it to raise an exception, but i find that its not doing so...
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Meenal Srivastva:
How do i ensure in my code that a file which is open should not be deleted?
I had expected it to raise an exception, but i find that its not doing so...


How are you opening the file in java?
On windows vista, if i open a file using FileInputStream/FileOutputStream, i can not delete the same from the file browser till the time the file is open.
 
Meenal Srivastva
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have'nt opened the file concerned in my code, what i mean is that the file might be open in a different editor, and if it is so, then i want to prevent its deletion.
I tried tryLock() method also, but its not recognising files which are open this way.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Meenal Srivastva:
I have'nt opened the file concerned in my code, what i mean is that the file might be open in a different editor, and if it is so, then i want to prevent its deletion.
I tried tryLock() method also, but its not recognising files which are open this way.

Try one thing, open the file in an editor and delete it from the file browser. (No java code involved!)
Both linux and windows allow such a deletion. (Tried with textpad in windows and vi in linux) So, i dont think you can do anything from the java code.
It depends on the editor as to how it opens the file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!