Java list files in resource directory




















IOException; import java. ArrayList; import java. Collection; import java. Enumeration; import java. Pattern; import java. ZipEntry; import java. ZipException; import java. FoxAlfaBravo 86 1 1 silver badge 12 12 bronze badges. Questioner knows how to implement it using standard java classes, but he wants to know how he can utilize existing Spring, Apache Commons libraries.

Jeroen Rosenberg There is also another way given which has been selected finally : — jmj. I find this solution useful for cases you don't use Spring - it would be ridiculous to add a dependency on Spring becuase of this feature only.

So, thank you! One might want to use File. Caveat: The java. You could alternatively look at the class loader and interrogate it for what URLs it's loading classes from. The other caveat of course is that if you're doing this under a SecurityManager, the ZipFile constructor can reject your access to the file, so you should be catching that. Show 2 more comments. I'd like to avoid to have this dependency just to perform this task. Reflections is not a Google library. Maybe it was in the past.

My answer is from and I did find some reference to the library using the phrase "Google Reflections" before I see the code has moved around a bit and has moved from code. NSduToit that was probably an artifact of hosting the code on Google Code not an uncommon mistake , not a claim of authorship by Google. You need to add better examples. It fails with org. ReflectionsException: Scanner ResourcesScanner was not configured for me.

Show 1 more comment. Jared Burrows Pavel Kotlov Pavel Kotlov 3 3 silver badges 11 11 bronze badges. Rob Rob 5, 30 30 silver badges 34 34 bronze badges. So use the example code if you want to check different location e. And why resourses are not files?

Resourses are files archived into zip archive. Those are loaded into memory and accessed in specific way but I can't see why they are not files. Any exaple of resource that is not 'a file within archive'? Luke Hutchison Luke Hutchison 6, 2 2 gold badges 35 35 silver badges 30 30 bronze badges. Great library with consistent behavior. Value; import org.

Resource; import org. It works for resources in the classpath, but not when they are in the JAR. Have search hours for that! Enrico Giurin 1, 27 27 silver badges 24 24 bronze badges. This received a downvote recently - if you found a problem with it, please do share, thank you! Thank you ArnoUnkrig - please share your updated solution if you like — fl0w. Used a combination of Rob's response. Charlie 7, 1 1 gold badge 51 51 silver badges 52 52 bronze badges.

Trevor Trevor 7 7 silver badges 16 16 bronze badges. Jacques Koorts Jacques Koorts 1, 1 1 gold badge 14 14 silver badges 10 10 bronze badges. In the linked documentation above: Specify the configuration options for the zip file system in the java. The documentation for the jdk. URI; import java. FileSystem; import java. FileSystems; import java.

Files; import java. Collections; import java. Deven Phillips Deven Phillips 1, 9 9 silver badges 39 39 bronze badges. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.

Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Visit chat. Learn more. How to list all files from the resources directory [duplicate] Ask Question. Asked 5 years, 10 months ago. Active 5 years, 9 months ago. Viewed 5k times. Improve this question. Community Bot 1 1 1 silver badge. Maxim Maxim 4, 8 8 gold badges 46 46 silver badges 75 75 bronze badges. Burkhard Not a duplicate to the referred question. Thank you for closing without help ignorant community members!

You could help at least with a right link if you took time to read the question. Add a comment. Active Oldest Votes. JarFile You can also use jar. Improve this answer. ManoDestra ManoDestra 5, 6 6 gold badges 23 23 silver badges 49 49 bronze badges.

Jar's resource directory. Thank you for links. Updated my answer to give an additional way of doing it via jar. Your hints brought me to this answer stackoverflow. Thanks for the help and I take it as an answer.



0コメント

  • 1000 / 1000