Quick Help with FileWatcher

I got a filewatcher to detect file changes, but i just cant get file.isFile() condition to pass.
public static void start() {
try {
WatchService watchService = FileSystems.getDefault().newWatchService();
Path scriptsFolder = Paths.get(SCRIPTS_FOLDER);

scriptsFolder.register(watchService,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY
);

SkReloader.getLog().info("Started FileWatcher! Scripts folder: '" + SCRIPTS_FOLDER + "'");

while (true) {
WatchKey key = watchService.take();

for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
Path path = (Path) event.context();

File file = new File(path.toFile().getAbsolutePath()); // if (!file.toFile().isFile()) return;
SkReloader.getLog().info(file + " " + file.getClass());
Script script = ScriptLoader.getScript(file);
...
public static void start() {
try {
WatchService watchService = FileSystems.getDefault().newWatchService();
Path scriptsFolder = Paths.get(SCRIPTS_FOLDER);

scriptsFolder.register(watchService,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY
);

SkReloader.getLog().info("Started FileWatcher! Scripts folder: '" + SCRIPTS_FOLDER + "'");

while (true) {
WatchKey key = watchService.take();

for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
Path path = (Path) event.context();

File file = new File(path.toFile().getAbsolutePath()); // if (!file.toFile().isFile()) return;
SkReloader.getLog().info(file + " " + file.getClass());
Script script = ScriptLoader.getScript(file);
...
the last line throws an exception (I have no permission to edit that class or method)
public static Script getScript(File file) {
if (!file.isFile())
throw new IllegalArgumentException("Something other than a file was provided.");
...
public static Script getScript(File file) {
if (!file.isFile())
throw new IllegalArgumentException("Something other than a file was provided.");
...
4 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @eren.! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
eren.
eren.OP9mo ago
been stuck on this for the past 20 minutes 😦
eren.
eren.OP9mo ago
this is what the .info() line prints
No description
JavaBot
JavaBot9mo ago
Post Closed
This post has been closed by <@587604022349791274>.
Want results from more Discord servers?
Add your server