简体   繁体   English

在Applet中使用Files.walkFileTree

[英]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.

相关问题 Files.walkFileTree中的遍历顺序 - Order of traversal in Files.walkFileTree 按字典顺序的Files.walkFileTree - Files.walkFileTree in lexicographical order 在上使用FOLLOW_LINK的Files.walkFileTree时出现无限循环 - Endless loop while using Files.walkFileTree with FOLLOW_LINK on Files.walkFileTree的并行版本(java或scala) - Parallel version of Files.walkFileTree (java or scala) 为什么 Java Files.walkFileTree 会抛出 NoSuchFileException? - Why Java Files.walkFileTree throw a NoSuchFileException? 使用Java NIO.2 FileVisitor和Files.walkFileTree(…)递归移动非空目录 - Moving not empty directory recursively using Java NIO.2 FileVisitor and Files.walkFileTree(…) 无法使用Files.walkFileTree在目录中打印子目录 - Can not print sub directory inside a directory using Files.walkFileTree java nio 如何使用 FileVisitor 接口以多线程方式使用 Java Files.walkFileTree()? - How can Java Files.walkFileTree() be used in a multiThread fashion using the FileVisitor interface? 使用Files.walkFileTree时,是否有任何方法可以跳过从搜索preVisitDirectory的位置开始的根文件夹? - Is there any way to skip the root folder from where the search starts for preVisitDirectory when using Files.walkFileTree? Files.walkFileTree 在某些 windows 文件上引发访问异常 - Files.walkFileTree throws access exception on some windows files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM