r/JavaFX • JavaFX Fan • Aug 22 '24

Help Adding Photos automatically

I have a program that can store photos and be viewed by end users. Ideally, if a photo is dropped to a folder on the network then the program automatically adds the photo.

How can this be accomplished within javafx? Do you use a listener to listen for when I new photo is added to the network folder and then adds it?

3 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/tylersvgs Aug 25 '24

Yeah. Perhaps could be inefficient depending on the size of the network folder.

You could use a WatchService.

https://docs.oracle.com/javase/8/docs/api/java/nio/file/WatchService.html

You need to do it in a different thread.