am trying to monitor a folder/file for any changes and then extract all the data from the file and append it to the database using java.
i have tried the watch service api in java to monitor the file as shown in the code snippet below.
import static java.nio.file.StandardWatchEventKinds.*;
import java.io.*;
import java.util.*;
public class FolderMonitor {
public void fileMonitor() throws IOException {
WatchService watchService = FileSystems.getDefault().newWatchService();
Path path = Paths.get("C:/Users/xxxxx/Desktop/yyyyy");
path.register(watchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE);
}
}
- The above snippet monitors the file path and shows that in the console if a main function is added or called in another method.
- So now i need to be able to read the data from that file whenever it is created or modified and then append the data to the database
Any help is highly welcome
so tihs is how i achieved this, i created various classes as shown below.
And this is how i read the properties file and parsed it to json
Currently those snippets do the monitoring and reading of the properties file and parse them to json format.
Now am remaining with using that json data to populate the database whenever there is change in the file.