access denied (java.io.FilePermission...)

Discussions

General J2EE: access denied (java.io.FilePermission...)

  1. access denied (java.io.FilePermission...) (1 messages)

    I keep getting this error when i try to read the content of a text file in my helper class for an entity bean.

    Can someone help me to solve this please. Thank You
  2. Entity beans are not supposed to access the file system directly, even for reads, because if you had an entity bean deployed in more than one machine in a cluster the behavior would depend on which computer it is installed in. This is something that the EJB spec tries to avoid.
    To solve your problem, you can place the file in some central HTTP server or something similar and grab it in your entity bean from there, or you can include the file in the EJB jar file and then grab it using MyEJB.class.getResourceAsStream(myFile). Both of these options make it so that when you update your EJB deployment, all cluster nodes get the updated text file. In the long run, although it's a little more tedious than just openning a file in some predefined location, this strategy could save you time and headaches in maintenance.