Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:36:27+00:00 2026-06-13T17:36:27+00:00

I have a collection of resources on the classpath something along the lines: com/example/foo

  • 0

I have a collection of resources on the classpath something along the lines:

com/example/foo
    r1.txt
    r2.txt
    r3.txt
    bar/
      b1.txt
      b2.txt
      baz/
       x.txt
       y.txt

I know that this package is on the class-path sitting in WEB-INF lib, what I want to able to traverse the class-path starting at com.example.foo looking for all the .txt files. Call a function with siganutre similar to the following.

List files = findFiles(“com/example/foo”,”*.txt”);

I am using spring 3.1 so I am happy to use any methods that are part of spring.

UPDATE:
Solution using Spring based @jschoen suggestion below:

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath:com/example/foo/**/*.txt");

The spring matches using ant style patters thus the need for the double **

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:36:28+00:00Added an answer on June 13, 2026 at 5:36 pm

    You can use the Reflections library if I am not mistaken.

    public static void main(String[] args) {
        Reflections reflections = new Reflections(new ConfigurationBuilder()
        .setUrls(ClasspathHelper.forPackage("your.test.more"))
        .setScanners(new ResourcesScanner()));
    
        Set<String> textFiles = reflections.getResources(Pattern.compile(".*\\.txt"));
    
        for (String file : textFiles){
            System.out.println(file);
        }
    }
    

    It doesn’t matter what package you put, you just need one to start with, and it will find all the others.

    EDIT: Also there seems to be PathMatchingResourcePatternResolver in Spring that you can use. It has a getResources(String locationPattern) that I would assume you could use the pass the pattern ".*\\.txt" and would work the same way. I don’t have Spring setup where I am at or I would have tested it out myself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I have this collection of images resources where that is stored in array, the
I have a collection that use as a cache. How can I limit the
I have a collection of Objective-C classes that get sub-classed at a variety of
I'm building a collection of RESTful resources that work like the following: (I'll use
I have a rails 3 nested resource defined as follows resources :candidates do collection
So I have a collection of objects that may be of multiple type. For
In routes.rb I have map.resources :groups, :collection => { :find_or_create => :get, :search =>
I have a problem configuring BASIC-auth in jetty here's my web.xml <security-constraint> <web-resource-collection> <web-resource-name>resources</web-resource-name>
I have a web app that has to do something every, let's say first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.