Where to create JSON file written from module (linux)

Hey everyone,

I have a module that writes a JSON file to a folder that the module creates in the data directory. When the file doesn't exist, my module creates the JSON file. On Windows this is \Ignition\data{myDirectory}. This works 100% of the time on Windows.
I use context.getSystemManager().getDataDir().getPath() to get the location, and it is agnostic, meaning it works on Windows and Linux installs.

An issue I'm having in Linux environments is the data directory doesn't allow me to write to it. My module can read and write to the file in that location with no problem, but cannot create the file to begin with.

I'm wondering if there is a better place to put this file, other than the data directory, without these Linux permissions issues, or if there is another way around this hiccup.

How are you creating your folder?

{Consider not using .getPath() on any File object--use that object's normal methods and constructors to manipulate paths in a platform-neutral way.}


The recommended pattern for persistent, non-configuration data (i.e. something your module wants to reference or cache, but should not be included in a gateway backup) would be $dataDir/modules/$yourModuleId/. The gateway service should absolutely have access to create files or directories in that folder, so I would echo Phil's question about exactly how you're creating the file(s).

1 Like

I looked and it looks like I am making the directory with the file if it doesn't exist like this

FileWriter file = new FileWriter(path);

where I should be creating a directory first and then the file like this

new File(path).mkdirs();

and then creating the file. I will give that a shot, thank you for the answer!