How to Lock a file

Hi,
I am using an XML file in my application, my application is basically an XML editor, so you can parse and change the XML file.
The problem is when the XML file is in use, i'll be able to do any operation on file, i can delete it, i can manually make changes on it.
Is there any way that I can lock my XML file when it is in use by my application, so you cannot delete or change it.
Thanks

Is there any way that I can lock my XML file when it
is in use by my application, so you cannot delete or
change it.you should probably look into apeing how Eclipse (and many other editors) behave - ie keep a local buffer of the file, and record when you read the buffer (or last saved). Then periodically and on interesting events (eg user refocuses window) you check to see if the local copy has been modified since you last looked (or deleted) and offer options to the user (eg "this file has been deleted - shall I close it" or "this file has been modified - shall I update it" etc..)
otherwise I think file locking is sorted out in 1.4 but have never personally used it (there is a FileLock class that looks interesting..)
http://www.google.com/search?hl=en&ie=UTF-8&q=lock+file+java&btnI=I%27m+Feeling+Lucky

Similar Messages

  • How to lock folders/files so pasword is required to open them

    Hi
    I've been asking around to find out how to lock a file or folder so that the user password is required to open them, but have had no luck as yet..
    can you assist?
    many thanks
    Mister Tom

    Mister Tom wrote:
    Hi
    I've been asking around to find out how to lock a file or folder so that the user password is required to open them, but have had no luck as yet..
    can you assist?
    many thanks
    Mister Tom
    If you run your system as a non-administrator, then the other user's folders are locked.
    If you then use Fast Switching, those folders are merely a mouse click (and password) away.

  • How to lock a file in solaris

    Hi everyone,
    Is there a way to lock a file in Solaris ?
    Any input highly appreciated.
    Tx
    Kaushalya

    Of course. There is even a class for it. However, be forewarned, locks only work when everything "plays nice". If one program locks it, and another program doesn't bother to attempt locking it before doing something with it, it will be able to "pull the carpet out from under" the locking process.
    If you mean "lock" in the "Windoof" sense (in that absolutely nothing can do absolutely anything with a file when something else has it locked), no.

  • Re: how to lock my file

    i just wonder how to add on security password to access to my confidential files ie bank e-statements, credit e-statement?
    thanks

    Click here and follow the instructions.
    (39683)

  • Locking a file

    i want to read a file . but before that i want to lock the whole file . how to lock a file ?
    how to do it in linux OS.

    Hello,
    You are probably looking for FileLock class...
    http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/FileLock.html
    Hope this helps

  • How do i find locked music files to solve my -54 error for windows 8

    everytime my itunes starts up, it comes up with " the ipod could not be synced, an unknown error occured (-54)", i've read that people find the locked files in their library and unlock them and it solves the problem, but i wanted to know how i find the files for a windows 8 pc?

    Maybe:
    https://answers.yahoo.com/question/index?qid=20090723091425AAM63Zz

  • I've been receiving an error message, "That the .itl file is locked, on a locked disc or you do not have write permission". Can someone tell me how to unlock the file or disc?

    I've been receiving an error message, "That the .itl file is locked, on a locked disc or you do not have write permission". Can someone tell me how to unlock the file or disc?

    theres no - in "itunes" its all one word
    try right clicking and running itunes as adminstrator or try on a different user account

  • File Lock - How to lock and unlock a file ? Can we do that for an FTP File?

    Hi All,
    I like to retrieve a file from the FTP server using Apache Commons Net libraries.
    for example if the file size is 20MB. When the file is in the progress of copying or transferring from the FTP server i need to lock the local file which is in our local directory so that no other process will use the same local file which is in the process of copying otherwise partially copied files will be used by another process.
    the file should be locked when it was in the progress of copying from the server. I have an automatic process which will access file objects at certain time and try to process the files.
    I like to know the simplest and easiest way to lock and unlock a file object locally which is trying to copy a file from the FTP server which is of huge size.
    And also i like to know how to lock and unlock a file in general?
    Thanks,
    J.Kathir

    we can set it read only only when it complete finishing the writing.
    can we able to make the file as read-only while transferring data to file.
    How to achieve it ? pls give me some sample code

  • How can I lock the file in use

    Dear All, I transfer the large text file to Solaris 10 server and copy the this file with transfer not success to another path. but I can open the file with end of file. How can I lock the file with transfer not successfully.

    Locking on UNIX is cooperative, not manditory. That means that all applications need to check for the lock explicitly and then not use the file if the lock exists.
    But if something is accessing the file beyond your control, locking isn't going to prevent it.
    If you do control all the access points, then take a look at lockf or flock functions.
    Darren

  • I cant remember the password to a locked PDF file.  How do I retrieve the password?

    I can't remember the password for a locked PDF file.  How do I retrieve the password?

    Hi Ihatepasswords,
    We do not have any option to retrieve the password or reset the password of the PDF file.

  • How could I convert a locked PDF file to Microsoft Word file?Uergency for exam!Need help!

    How could I convert a locked PDF file to Microsoft Word file? Because of locking, I could not print it. Uergency for examination! Need help from veteran!

    Adobe do not offer any products, or help, in hacking protected files.

  • Adobe Reader X: How to disable resource file locks of PDFs

    Hi,
    I develop PDFs using LaTeX tools, and like to view my PDFs with Adobe Reader X (I am currently using version 10.1.0.534) on Windows XP.
    Unfortunately, I cannot compile my LaTeX documents using pdflatex (or otherwise) when the file these tools are trying to write to are open by Adobe Reader X, which appears to place a resource lock on open files.
    Is there any configuration option to prevent the Reader X from placing a resource lock on files? It is frustrating to have to manually close and re-open the reader whenever I recompile my PDFs that I am resorting to other PDF readers, like Sumatra or Foxit, which don't place locks on PDFs they read.
    I understand that the resource lock may be a solution for dealing with problems related to ActiveX components for IE, but I only use Chrome and Firefox, so this is an unneccessary and annoying behaviour.
    Thanks in advance,
    Ratzski

    Thanks for your suggestion, but doing this (kind of thing... as I couldn't exactly follow your instructions as they aren't visible in Reader X 10.1) didn't work.
    Can anyone else offer any suggestions?

  • How to I lock a file so that it can't be editored by someone else?

    I have done a large file for a sign and I don't want the sign company to be able to edit the file.  The image is 3m x 1m so it's a large file.

    Having the file saved as a Photoshop PDF would allow you to password lock the file for edits, yet still print it commercially.
    I have High Quality Print as a preset, but there is a Press Quality setting.

  • How to exclusively lock a file in java

    Here,
    I am trying to lock a file before finished writting data to it;
    At the mean time there is a C-language daemon is try to grep the data from the file.
    The synchronized code:
    synchronized(theFile){
    pWriter = new java.io.PrintWriter(new
    java.io.FileWriter(theFile));
    pWriter.write(fileContents);
    pWriter.flush();
    pWriter.close();

    synchronized is used to synchronize threads in the current process. A daemon is not in the same process so it will have absolutely no impact.
    Locking a file is OS dependent so you will have to craft a solution appropriate for the OS you are on. And you will probably have to use JNI to do it. Presumably your OS supports locking.

  • How do I share files uploaded into the Creative Cloud with other creative cloud members?

    How do I share files uploaded into the Creative Cloud with other creative cloud members?

    Should be easy.  Try this...
    In Thumbnails view, click the little triangle (pointing downward) in the lower-right corner of the asset you want to share.
    In the blue icon bar that appears, click the Share icon (the third icon from the left, just right of the trash icon). The Share dialog should pop up.
    In the Share dialog, enter the email address of the person with whom you want to share the asset, then click the Send Email button - they'll receive an email with a link to your asset. OR
    You can also copy a link to the asset and then paste that into your own email client if you prefer.  To do that, click the Link icon (looks like a "chain", and is to the right of the email "envelope" icon) - then click the Copy Link button.
    Note that the Share options won't be available if your asset is set to "Private" - you can control whether an asset can be viewed (or downloaded) by others by clicking the Public/Private control (green or red "lock" icon).
    You can also access the same Share controls if you click on the file to see it one-up (you can do this from either Thumbnails view or List view); click the Share icon near the upper right corner of the browser window (to the right of the asset name).
    Hope that helps.

Maybe you are looking for