I have a specific requirement to read a resource from jar file and then write it to local disk. But when I try to write that resource to local disk an exception:
java.io.FilePermission (write) is raised.
I have my jar signed. I have also tried the following solution but it does not work either.
AccessController.doPrivileged(new PrivilegedAction()
Nothing seems to work.
Am I missing a step after signing jar because this is the most common solution available everywhere?
How can I write to a local file without using policy files (because that can’t be done on each client machine)?
The JNLP also needs to specify:
See the JNLP File Syntax for details.
I would generally use the
FileSaveServiceas detailed in Tom’s answer, but this sounds more like a situation where the ‘file’ could be a default properties file for configuring the app. The save service is not well suited to that, since the app. has no way to know where the file is stored, or how to access it later. For security reasons, theFileContentsobject that is provided in place of aFilehas no methods that return the path.In that case, extract the details of the config. file & store them using the
PersistenceServiceof the JNLP API. Here is a demo. of thePersistenceService. This service is also available to sand-boxed apps. (no code signing voodoo).