File lockFile = new File ( "lock.lok" );
if ( lockFile.createNewFile() )
   {
   // You now have the lock file -- it is create, so do
   // what you want to the data file
   // Delete the lock file when you're done
   lockFile.delete();
   lockFile.deleteOnExit();
   // A good fail-safe for releasing the lock
   }
else
   {
   // The lock file already exists, so you can't access the data file right now.
   // Go away and try again later.
   }