I drop an xml file in the scanFolder of a windows machine and java watches that file creation event and triggers my processFileMethod.
if(event.kindOf("create") {
processFile (filePath); // call process file from watcher service
}
processFile(Path filePath) {
FileInputStream fileInputStream = null;
File inProcessFile = new File(filePath.toString());
// inprocess file exists at this point
try
{
fileInputStream = new FileInputStream(inProcessFile);
} catch (Exception e)
{
// filenotfoundexception thrown.
} finally {
fileInputStream.close();
}
}
Problem
Something is holding onto the file (windows native ?). Applying a breakpoint gives it enough delay but without it raises an exception.
Tried - file.canRead, canWrite, canExecute, exists - all checks before the instantiation to verify.All return true.
Exception:
\java.io.FileNotFoundException: C:\scanFolder\File (4) - Copy.xml (The process cannot access the file because it is being used by another process)