0

A user wants to copy big files some gigabytes in java and I want to monitor the process to provide some kind of information, when the process is done.

I am monitoring the file system to check when a new file is created, modified or deleted. However, when a big file is transferred, I get a lot of "ENTRY_MODIFY" events - I would like to see the "ENTRY_CREATE" event (Which is done) and then I need some kind of mechanism that waits until the copy process is done.

Up to now I have a solution like this in my code for "ENTRY_CREATE":

            long oldSize = f.length();
            long newSize = -1;
            while(oldSize!=newSize)
            {
              oldSize= newSize;
            }
              newSize = f.length();

Any suggestions for this?

Thank you

Peterchen
  • 31
  • 4
  • 2
    Look up ProgressMonitorInputStream – nullByteMe Jan 29 '15 at 20:01
  • OK - the copy process is initiated by some user in the system for example by pressing ctrl+c ctrl+v in that folder. Copy is not really done by the java program – Peterchen Jan 29 '15 at 20:08
  • are these JVM events or OS events? – Paul Nikonowicz Jan 29 '15 at 20:10
  • What exactly is the point of that `while` loop? An `if` statement would be more to the point. Nobody is going to magically change `newSize` while the loop is running, if that's what you're thinking. – user207421 Jan 29 '15 at 20:26
  • @EJP yeah there was one statement missing, but this doesn't solve the problem – Peterchen Jan 29 '15 at 20:33
  • @Peterchen For example you need one proccess bar to show you how bytes are writen , in how many time , etc and when this proccess is done your program to say "done"? – crAlexander Jan 29 '15 at 21:35
  • @crAlex Yep - like this, but the copy process is initiated by the OS – Peterchen Jan 30 '15 at 06:34
  • i think you know how to copy a simple file in java? if not let me know show i will include an answer with this and some more.. – crAlexander Jan 30 '15 at 14:31
  • @crAlex Yes of course I now... But the file is not copied by the java program. The file is copied by an external program or by the user (CTRL+C, CTRL+X). I am able to get an event when the copy is initiated, but I don't have an idea to check when the copy is done. – Peterchen Jan 30 '15 at 16:10
  • so man (i thought you wanted to copy with java) ok then.... – crAlexander Jan 30 '15 at 21:04

0 Answers0