Error when trying to write a file

Hey everyone,   I have a custom java code that requires me to write a file. When I run the app locally, i don’t run into any problems. However, once i deploy, I get the following error message; com.mendix.systemwideinterfaces.MendixRuntimeException:java.nio.file.AccessDeniedException: cdv_photo_002.jpg The code in question is:   // Write bytes to files  //String filePath = "c:\\temp\\" + fileName;  String filePath = fileName;  Path path = Paths.get(filePath);  Files.write(path, fileBytes);    What am I doing wrong?   Thanks in advance!
1 answers

Hi Tom,

Mendix cloud servers are Linux based so your file path will not exist.

There are also permission limitations as to which folders you can write files too. If you really need to write files you may write files to the temp directory. You can get the basepath for the temp directory via the following piece of code:


Files in the temp directory will be removed with each restart. 

But I like to try and change your perspective. Why do you want to write a file directly? Why not create a FileDocument or Image (based on System module) object and write the file contents to that file via the functions you have for such objects.

This would let you benifit from the infrastructure Mendix offers when working with files.