ClassLoader.getResources(name)
(veya statik sürüm ClassLoader.getSystemResources(name)
) gerekir.
Ancak maalesef "dizin" içinde olmayan kaynaklarla ilgili bilinen bir sorun var. Örneğin. foo/bar.txt
iyi, ancak bar.txt
bir sorun olabilir. Bu, described well in the Spring Reference olup, hiçbir şekilde Spring'e özgü bir sorun değildir.
Güncelleme:
İşte InputStreams listesini döndürür, yardımcı bir yöntem var:
public static List<InputStream> loadResources(
final String name, final ClassLoader classLoader) throws IOException {
final List<InputStream> list = new ArrayList<InputStream>();
final Enumeration<URL> systemResources =
(classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader)
.getResources(name);
while (systemResources.hasMoreElements()) {
list.add(systemResources.nextElement().openStream());
}
return list;
}
Kullanımı:
List<InputStream> resources = loadResources("config.properties", classLoader);
// or:
List<InputStream> resources = loadResources("config.properties", null);
Cool ile alabilirsiniz. Teşekkürler! Bir InputStream almak için bu URL'lere nasıl devam edeceğinize bir örnek ekleyebilir misiniz? – Zeemee
@Mulmoth: "URL" sınıfının, bu URL için bir InputStream döndüren bir "openStream" yöntemi vardır. İhtiyacın olan her şey bu olmalı. –
@Mulmoth Güncellememi görün –