One approach is to try to make an exclusive file lock when it is opened. When your other application instance tries to open the file, an IOException will be thrown. You can catch this exception and show your user a message that the file is already open in another application. This scenario should be considered in any case, since the file may be opened in another application that does not belong to you.
source share