Question

I'm working on the applet that reads data files from one specific folder (lets call it 'Data folder'). Number of files and their names can change over time so I don't want to add them rigidly into the code. I would like to be able to list all the files stored in that folder (note: folder is stored on the same server as applet). I tried to do that using Files.walkFileTree method. It worked just fine when I ran it in the Eclipse but I got AccessControlException:

java.security.AccessControlException: access denied ("java.io.FilePermission" "Data folder" "read")

when I tried to run in the browser.

I can see why would jvm want to restrict applets from listing files on local computer but is it possible to list files stored on the server?

Was it helpful?

Solution

You have to distinguish between client side and server side code. Your applet is executed at client side, so it is unable to access the server's file system directly with Files.walkFileTree(). What you can do is to implement a service (like a REST service or a simple servlet) and run it on server side in a Tomcat or Jetty servlet container and then call this service from your applet. But be careful to make your service secure, so that it is not allowed for erveryone to see your server's whole file system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top