This content has been marked as final. Show 2 replies
What is a PrematureEndOfFile exception? I've never seen that before and as far as I know it doesn't exist in the JDK (not even in 7).
Writing files is not an atomic operation, so an FTP server usually creates the file first, then writes the content. This means that just because a file has been created does not mean that the content will be "complete".
The reason you didn't see this when dropping files into a local folder is probably because moves within a file system (= drive in Windows, usually) are atomic, so you won't ever see a "half-moved" file. Try copying into the folder and you should be able to see the same effect (within a shorter time, however since local copies are usually very fast).
There's no reliable way to know when an application is "done" writing a file and NIO2 doesn't change that.
Ideally, you could configure your FTP server to write its files to some temporary name and rename it to the final name once the transfer is complete. Then you can just ignore all events where the name matches the temporary files.