[英]How to get all files in a directory in java applet?
I know how to get all files in a directory in a local app, but when it comes to applet, it doesn't seem to work too well. 我知道如何在本地应用程序的目录中获取所有文件,但是当涉及到applet时,它似乎并不能很好地工作。
The way I normally do: 我通常的做法:
File file = new File("myDirectory");
File[] files = file.listFiles();
I tried the same thing and it didn't work for my applet. 我尝试了同样的事情,但对我的小程序却不起作用。 My src has the standard maven project structure.
我的src具有标准的maven项目结构。 ie:
即:
src\main\java\mypackage\MyApplet.java
src\main\resources\myDirectory\<... bunch of files here...>
So how do I get all the files in myDirectory from MyApplet.java? 那么,如何从MyApplet.java获取myDirectory中的所有文件?
Get directory 获取目录
File directory = new File(getClass().getResource("/myDirectory").getFile());
list files 列出文件
f.listFiles();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.