• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Java event on placing a file in a folder?

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a requirement to store an image/text file in Database whenever a new file is dropped in a particular folder in filesystem. One way could be to use a thread that will scan the folder after a particular time period. Is it possible to listen to an event that will be generated whenever a file is placed? That way I wont have to continously scan and the thread will wakeup only when a file is actually placed.
Thanks,

Kapil
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless there's something new in the latest version of Java, there is no pure Java way to get notified of files arriving in folders. Therefore, your choices are to periodically scan the folder, as you suggest, or to write native code to pick up your particular platform's native events on file movements, then interface that to your Java with JNI.

I've done a file scanner previously with success. You need to take care that the file has finished copying before trying to process it. Look at the size of the file over several scans, before concluding it's stable. Otherwise, you may try to process half a file.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic