/** * Return true if the fils exists and is readable and writable not locked by another process <br> * New version that works because it uses RandomAccessFile and will throw an exception if another * file has locked the file */ public static boolean isUnlockedForWrite(File file) { if (file.exists() && file.canWrite()) { if (file.isDirectory()) { return true; } try { RandomAccessFile raf = new RandomAccessFile(file, "rw"); raf.close(); debug(new Date() + " " + file + " OK!"); return true; } catch (Exception e) { debug(new Date() + " " + file + " LOCKED! " + e.getMessage()); } } else { debug( new Date() + " " + file + " LOCKED! File exists(): " + file.exists() + " File canWrite: " + file.canWrite()); } return false; }