Java.io.FilePermission : Access denied

0
Hello everybody, I want to create a file with a custom Java Action. Like this. //encodedString is the content of my future file in base64 byte[] decoded = java.util.Base64.getDecoder().decode(encodedString); File file = new File("test.txt"); FileOutputStream fos = new java.io.FileOutputStream(file); fos.write(decoded); fos.flush(); fos.close(); FileInputSt"eam fileInputStream = new FileInputStream(file); return new String(decoded); But with that code I have an error from the accessControl  "java.security.AccessControlException: access denied ("java.io.FilePermission" "test.txt" "write")". How can I create my file ? Perhaps the folder is protected.  
asked
2 answers
1

You only have a few places where you can create files. You can get them through the configuration, e.g.

Core.getConfiguration().getTempPath()

There is also a getResourcesPath() method that may return a writable location. You can find the Java apidocs here. Be aware that when writing code with paths, you should take appropriate measures to deal with file separators, since most people work locally on Windows and standard cloud environments run Linux, e.g.

Core.getConfiguration().getFileSeparator()

If you want to persist these files, you should use the System.FileDocument entity,

answered
0

Thank you ! TempPath is fine for me. 
I just want to compare a file create with my Java action and a fileDocument create with the communityCommon java action StringToFile with the same String content.

In result they are big difference my file is readable and the fileDocument is unreadable... 
If someone can explain me why the fileDocument is unreadable. 

Here i create the fileDocument and download it 

Here I create the my file and I return string i use in java action StringToFile (above)

Then when I compare the FileDocument and my file 

We can see a big difference of content and size... On the left is my file created in the java action and on the right the FileDocument.

 

Someone have an idea how I have this difference ?

 

answered