Getting access denied error for path when trying to access file with java action i.e FileDocumentFromFile

0
I have a file which I have added in project_directory/resources/Configuration folder. I had JA_GetResourcePath which returns correct path to me for file in my local. I wanted to store that file in mendix app by using FileDocumentFromFile java action but when I am using this java action (FileDocumentFromFile), it's giving below error related to access. I checked the permissions for user role which were correct only and also tried to run studio pro with Admin role.Please assist here if encountered similar scenario.Error occured while uploading json instructions file.Error details: com.mendix.systemwideinterfaces.MendixRuntimeException: java.io.FileNotFoundException: C:\Users\Vivek\Mendix\SampleAppTCSMendix10\deployment\model\resources (Access is denied) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:126)Caused by:java.io.FileNotFoundException: C:\Users\Vivek\Mendix\SampleAppTCSMendix10\deployment\model\resources (Access is denied) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:126)Caused by:C:\Users\Vivek\Mendix\SampleAppTCSMendix10\deployment\model\resources (Access is denied) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:126)
asked
2 answers
1

This is not a Mendix user role issue. It is a Windows file system access issue.


You should not read files directly from deployment\model\resources. That folder is managed by the runtime and may not allow direct access.


Instead, read the file from project_directory/resources using a resource stream (classpath) in Java, or copy the file to a safe folder like deployment\data and then use FileDocumentFromFile.


Do not use the deployment\model\resources path directly.


If this resolves the issue, please close the topic.


answered
0

Hi,


This issue is not related to user role permissions or running Studio Pro as Administrator.

The error occurs because you are trying to access a file inside:


deployment/model/resources

using a direct filesystem path. In Mendix, files inside the resources folder are packaged into the model and are not meant to be accessed via raw file paths at runtime.

That is why you are getting:


java.io.FileNotFoundException (Access is denied)

The runtime does not allow direct file system access to that directory.

Why It Works Locally but Fails in Runtime

When you use JA_GetResourcePath, it may return a valid path during development, but at runtime:

  • The model is packaged as an archive.
  • Resources are bundled inside the deployment.
  • Direct file system access to that location is restricted.
  • You cannot treat it like a normal Windows folder.

Mendix does not guarantee file-level access to deployment/model/resources.

Correct Way to Access Files from Resources Folder

You must use getResourceAsStream(), not File paths.

In a Java action:


InputStream is = this.getClass().getClassLoader().getResourceAsStream("Configuration/yourfile.json");

Then use the stream to create a FileDocument.

Example:


IMendixObject fileDoc = Core.instantiate(context, "System.FileDocument");

Core.storeFileDocumentContent(context, fileDoc, "yourfile.json", is);

This is the correct and supported approach.

Important Rules

  1. Never access deployment/model/resources directly.
  2. Do not use absolute Windows paths.
  3. Always use classloader resource streams.
  4. Files inside resources are read-only.
  5. For writable files, use the data/tmp directory instead.

If You Need Writable File Access

Use:


Core.getConfiguration().getTempPath()

This gives a valid writable runtime path.


The error happens because you are attempting direct filesystem access to a packaged model resource.

In Mendix, resources must be accessed via getResourceAsStream() using the classloader.

Switching to stream-based access will resolve the issue completely.

answered