KB-20071122-035
From Triled Wiki
- Status: respond received
- author: Andrew Zhang
- link: http://groups.google.com/group/android-developers/msg/6c249674df666c90
- Description: FileLock.release throws IOException
- Steps to reproduce:
Code is taken from original post
public void testFileLock() throws Exception {
String fileName = getDataDir() + "/fileLock.test";
RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
FileLock lock = raf.getChannel().tryLock();
raf.write("hello,world".getBytes());
lock.release();
raf.close();
}
Unexpected behaviour: throws IOException.
[edit] Temporarily solution
suggested by Andrew Zhang.
insert "raf.seek(0)" before unlocking:
raf.write("hello,world".getBytes());
raf.seek(0); // workaround
lock.release();
Note: Need confirmation on newer SDK.
