[英]Using Files.walkFileTree in Applet
I'm working on the applet that reads data files from one specific folder (lets call it 'Data folder'). 我正在研究从一个特定文件夹中读取数据文件的applet(我们称之为“数据文件夹”)。 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). 我希望能够列出该文件夹中存储的所有文件(注意:文件夹与applet存储在同一服务器上)。 I tried to do that using Files.walkFileTree method. 我尝试使用Files.walkFileTree方法来做到这一点。 It worked just fine when I ran it in the Eclipse but I got AccessControlException: 我在Eclipse中运行它时工作得很好但是我得到了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? 我可以看到为什么jvm想要限制applet在本地计算机上列出文件,但是是否可以列出存储在服务器上的文件?
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()
. 您的applet在客户端执行,因此无法使用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. 您可以做的是实现一个服务(如REST服务或简单的servlet)并在服务器端在Tomcat或Jetty servlet容器中运行它,然后从您的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. 但要小心使您的服务安全,以便不允许每个人看到您的服务器的整个文件系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.