Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to monitor file transfer in Windows using Java?
    primarykey
    data
    text
    <p>I am writing a utility to check whether a very big file has been completely transferred.</p> <p>From what I found online, I understand that the best way is to have the sender send a bite-sized file to indicate that a file transfer is complete. For instance, after sending a 10GB video file <code>bigfile.mov</code>, the sender then sends a 1KB <code>bigfile.txt</code> containing the checksum or something to identify the file; the receiver then polls for <code>bigfile.txt</code>.</p> <p>However, in my case, this approach is not open to me because I have no control of the files being sent to me. Therefore I am resorting to the much more unreliable approach of polling a file a certain number of times in specified intervals, for its file size and last-modified time.</p> <pre><code>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()) { for (int i = 0; i &lt; polls; i++) { // sleep a 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; } </code></pre> <p>I am writing this utility on Windows, and I test this by copying a very large file from a temp location to where I want it (say <code>C:\bigfile.mov</code>). The problem is that, once the file copying begins, it seems that both the file size AND the last-modified time are locked in, so even when I test this method while the file is still being copied, I still get <code>true</code> as my result (which is obviously not the case).</p> <p>How should I change my code in this case?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload