AccessControlException: access denied (java.io.FilePermission ..... read)
Now, I understand that this is a security issue to protect the clients system from malicious access to their machine but what I don't get is that I am trying to access images that are in the same directory as the applet classes, not client files. I don't want to create or change any files on the local machine. Is there a simple way around this by using certain pathname conventions or something. At the moment I am just using the image filename since all the files are in one directory.
Any help greatly appreciated.
Originally posted by Joe Ess:
Imagine your client is on one computer and your web server is on another. How would you find the image files when they're on the server's file system?
This is why I don't understand the problem. If the client downloads an applet class from the server then it must know the address that it came from. Therefore if I keep all the image files in the same directory as the applet class why should there be a problem if I try to reference the files using purely the filename and no path?
I also tried using the full URL of the image on the server but then I get a Socket Permission error at the target URL.
I just want to put my own icons on some buttons on my applet. Why is there a security issue trying to do this and what is the easiest way to rectify the problem?
[ March 28, 2005: Message edited by: Chris Robinson ]
Originally posted by Chris Robinson:
This is why I don't understand the problem. If the client downloads an applet class from the server then it must know the address that it came from.
You can FIND the address it came from (through Applet.getDocumentBase() or Applet.getCodeBase()) but that doesn't mean that all file system requests automatically get converted into network requests. Code does what you tell it to do. A FileInputStream ALWAYS accesses the file system. If you construct a URL you have to get the host address that you want to access and feed it to the URL constructor. Applets are only permitted to contact the host they were downloaded from, so plugging anything else in there will cause a security exception. If this doesn't make sense, share a sample of your code trying to load an image from a URL and we'll work through it.