-1

I have a java code that monitors files in a folder, the files are dropped by ftp from another system via a table. How do i ensure that i do not pick up incomplete files? The files dropped are XML files.

jabsy
  • 19
  • 1
  • 7

1 Answers1

0

Try to lock the file. If it is not complete, you can not lock it:

private boolean isFileComplete(File file) {
    FileLock lock = null;
    FileChannel channel = null;
    try {
        channel = new RandomAccessFile(file, "rw").getChannel();
        lock = channel.lock();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        if (lock != null)
            try {
                lock.release();
                channel.close();
            } catch (IOException e) {
                //Keine Behandlung Notwendig
            }
    }
    return true;
}

If it is lockable, the file is complete.

Jens
  • 67,715
  • 15
  • 98
  • 113