java - FileInputStream causing FileNotFoundException - The Process cannot access the file -


i using watcher service let me watch addition or removal of files particular directory. far have working adding file , deleting file. seeing stacktrace (java.io.filenotfoundexception: c:\data\index.php (the process cannot access file because being used process) when add file, remove file, retry adding file again.

here's code in question error happening within try block of getdigest method:

public class watchdir implements runnable{          (watchevent<?> event: key.pollevents()) {             watchevent.kind kind = event.kind();              // context directory entry event file name of entry             watchevent<path> ev = cast(event);             path name = ev.context();             path child = dir.resolve(name);              if(!files.isdirectory(child, nofollow_links)){                 //callable<lftfile> worker;                  try {                     **this.file = new lftfile(child.tofile(), kind != entry_create);**                      if(this.file.isdeleted()){                         // update db, set deleted flag                                    } else {                             // add db                         }                                         } catch (exception e1) {                     logger.error("...");                 }                                }  ... ...     } }         // method within lftfile.  reads in file's content     // , creates crc on it.  future validation. private static long getdigest(file f) {     long crc = -1;     try ( **inputstream in = new fileinputstream(f)** ) {   // <--- errs here         crc32 crcmaker = new crc32();         byte[] buffer = new byte[2048];         int bytesread;         while((bytesread = in.read(buffer)) != -1) {             crcmaker.update(buffer, 0, bytesread);         }         crc = crcmaker.getvalue();       } catch (exception e) {         e.printstacktrace();     }        return crc; } 


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -