java – Checking for adding a file to a folder

Question:

I have a service that must constantly check a specific folder, and when adding a file to a folder, it must perform certain actions. Question: how to catch the event of adding a file to a folder?

Answer:

Took the answer from the link in the comment to my question:

observer = new FileObserver("путь до папки") { 

             @Override
             public void onEvent(int event, String file) {
                if(event == FileObserver.CREATE){ 

                 "какое-либо действие при добавлении файла"

                 }
             }
         };
observer.startWatching();
Scroll to Top