Imagine you are writing an application that must be restricted to running a single instance on a single machine.
To implement this requirement, you have decided to lock a file when the application starts.
If the lock attempt fails, the code generates a message and shuts down the new instance of the application.
You have decided to use the FileLock class obtained from the FileChannel class to implement this, as follows:
How can you get an instance of the FileChannel to accomplish the requirement?
Assume the rest of the code is valid and the file exists on the file system. Choose one.
- A. fos.getChannel();
- B. new FileChannel(fos);
- C. FileChannel.open(fos);
- D. FileSystemProvider.newFileChannel(fos);
·Ɐ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnๅɔuoꓛ