I recently added file blocks to my asynchronous download:
FileOutputStream file = new FileOutputStream(_outFile); file.getChannel().lock();
and after the download is complete, file.close() to release the lock.
From the called BroadcastReceiver (another thread), I need to go through the files and see which ones are downloaded and which are still locked. I started with trylock:
for (int i=0; i<files.length; i++) { try { System.out.print((files[i]).getName()); test = new FileOutputStream(files[i]); FileLock lock = test.getChannel().tryLock(); if (lock != null) { lock.release();
Unfortunately, I read that the file is truncated (0 bytes) when creating FileOutputStream. I set it to add, but the lock does not seem to take effect, everything seems not to be locked (fully loaded)
Is there another way to check if file write lock is currently in use, or am I using the wrong methods here? Also, is there a way to debug file locks from an ADB or Eclipse terminal?
source share