Hi again,
I am using the following code to read an object from a file:
Quote:
FileInputStream fis = new FileInputStream(USERS_DB_PATH);
ObjectInputStream ois = new ObjectInputStream(fis);
FileLock lock = fis.getChannel().tryLock();
if(lock != null)
{
users = (UsersDatabase) ois.readObject();
lock.release();
}
|
and I get the following exception
Quote:
Exception in thread "main" java.nio.channels.NonWritableChannelException
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:773)
at java.nio.channels.FileChannel.lock(FileChannel.java:865)
|
Any ideas why and how can I avoid it?