Can I read a local file in an openHAB JS rule?

Yes, but you have to import and use the Java IO classes to do it. If it’s just plain text a quick and dirty way to read in the file is

var fileContents = actions.Exec.executeCommandLine(time.Duration.ofSeconds(5), 'cat', '/path/to/file');

If it’s binary, you’ll need to create a Java FileInputStream and read in and manipulate the bytes using those Java classes.

Java file IO is complicated. There’s no simple example I can show because what classes you need to use and how you read the data depends on the format of the file and what you want to do with it.

https://raw.githubusercontent.com/rkoshak/openhab-rules-tools/refs/heads/main/rule-templates/lastShutdownTime/lastShutdownTime.yaml

The above is a direct link to the code for Last Shutdown Timestamp [5.0.0.0;5.9.9.9] which finds the most recent events.log archive file, reads the last line of the gzip events.log file, and gets the timestamp of the last entry to get a rough estimate of the last time OH was running before it was started.

There are tons of tutorials on Java file IO on the web.

All actions taken, whether through executeCommandLine or the Java File IO classes will be running as user openhab so user openhab will need permission to read the file in question.