How to monitor file transfer in Windows using Java? -
i writing utility check whether big file has been transferred.
from found online, understand best way have sender send bite-sized file indicate file transfer complete. instance, after sending 10gb video file bigfile.mov
, sender sends 1kb bigfile.txt
containing checksum or identify file; receiver polls bigfile.txt
.
however, in case, approach not open me because have no control of files being sent me. therefore resorting more unreliable approach of polling file number of times in specified intervals, file size , last-modified time.
public static boolean hasfinished(string sfilename, int polls, int interval) { boolean isdone = true; file file = new file(sfilename); long size = file.length(); long lastmodified = file.lastmodified(); if (file.isfile()) { (int = 0; < polls; i++) { // sleep bit try { timeunit.seconds.sleep(interval); } catch (interruptedexception e) { e.printstacktrace(); } system.out.println("checking..."); if (file.length() != size || file.lastmodified() != lastmodified) { isdone = false; break; } } } return isdone; }
i writing utility on windows, , test copying large file temp location want (say c:\bigfile.mov
). problem that, once file copying begins, seems both file size , last-modified time locked in, when test method while file still being copied, still true
result (which not case).
how should change code in case?
Comments
Post a Comment