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.