public static List<String> getFilenamesInDir(String dir) {
List<String> filenames = new ArrayList<String>();
try {
if (dir.startsWith("/")) {
dir = dir.substring(1);
}
Enumeration<URL> urls = ClassPathHelper.class.getClassLoader().getResources(dir);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
String protocol = url.getProtocol();
if (protocol.equals("file")) {
File dirFile = new File(url.toURI());
HashMap<File, String> files = listFiles(dirFile, dir);
if (files != null) {
for (Map.Entry<File, String> entry : files.entrySet()) {
String filename = entry.getValue() + entry.getKey().getName();
filenames.add("/" + filename);
}
}
}
if (protocol.equals("jar") || protocol.equals("zip")) {
String file = URLDecoder.decode(url.getFile(), "UTF-8");
int bangIndex = file.indexOf('!');
String jarPath = file.substring(bangIndex + 2);
file = new URL(file.substring(0, bangIndex)).getFile();
ZipFile zip = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().startsWith(dir.substring(1)) && !entry.isDirectory()) {
filenames.add("/" + entry.getName());
}
}
zip.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return filenames;
А через него можно получить просто список файлов в нужной папке ресурсов?Файлы ты никак не получишь, только InputStream. Подойдет?
getClass.getResourceAsStream(...)
Вапще не видно?Ну допустим есть такой вариант
Этот код я просто скопипастил из кода ск. Мб у тебя он даже не запустится, но можешь попробовать даяда.Java:public static List<String> getFilenamesInDir(String dir) { List<String> filenames = new ArrayList<String>(); try { if (dir.startsWith("/")) { dir = dir.substring(1); } Enumeration<URL> urls = ClassPathHelper.class.getClassLoader().getResources(dir); while (urls.hasMoreElements()) { URL url = urls.nextElement(); String protocol = url.getProtocol(); if (protocol.equals("file")) { File dirFile = new File(url.toURI()); HashMap<File, String> files = listFiles(dirFile, dir); if (files != null) { for (Map.Entry<File, String> entry : files.entrySet()) { String filename = entry.getValue() + entry.getKey().getName(); filenames.add("/" + filename); } } } if (protocol.equals("jar") || protocol.equals("zip")) { String file = URLDecoder.decode(url.getFile(), "UTF-8"); int bangIndex = file.indexOf('!'); String jarPath = file.substring(bangIndex + 2); file = new URL(file.substring(0, bangIndex)).getFile(); ZipFile zip = new ZipFile(file); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().startsWith(dir.substring(1)) && !entry.isDirectory()) { filenames.add("/" + entry.getName()); } } zip.close(); } } } catch (Exception e) { e.printStackTrace(); } return filenames;