• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File which is open should not be deleted?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic