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 8393161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:42:40+00:00 2026-06-09T19:42:40+00:00

My Java application needs to be able to find a myconfig/ directory which will

  • 0

My Java application needs to be able to find a myconfig/ directory which will be bundled inside the same JAR:

myjar.jar/
    com/
        me/
            myproject/
                ConfigLoader.java --> looks for myconfig/ directory and its contents
    myconfig/
        conf-1.xml
        conf.properties
        ... etc.

How do I actually go about reading this myconfig/ directory off the runtime classpath? I’ve done some research and it seems that the normal method of reading a file from the classpath doesn’t work for directories:

InputStream stream = ConfigLoader.class.getResourceAsStream("myconfig");

So does anyone know how to read an entire directory from the runtime classpath (as opposed to a single file)? Thanks in advance!

Please note: It is not possible to load the files individually, myconfig is a directory with thousands of properties files inside it.

  • 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-09T19:42:41+00:00Added an answer on June 9, 2026 at 7:42 pm

    You can use the PathMatchingResourcePatternResolver provided by Spring.

    public class SpringResourceLoader {
    
        public static void main(String[] args) throws IOException {
            PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    
            // Ant-style path matching
            Resource[] resources = resolver.getResources("/myconfig/**");
    
            for (Resource resource : resources) {
                InputStream is = resource.getInputStream();
                ...
            }
        }
    }
    

    I didn’t do anything fancy with the returned Resource but you get the picture.

    Add this to your maven dependency (if using maven):

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java application which needs to read and write files to HDFS.
I need to write a standalone Java application which will have a embedded HTTP
I'm writing a java application which needs to perform an unusual login procedure. One
I have a Java application that needs to collect and report a large number
I'm developing a Java application that uses java.util.logging for its logging needs. This application
I am writing a java application that takes schema-bounded XML as input and needs
I am developing a Java Desktop Application . This app needs a configuration to
I need to write a MultiThreaded Java Application that will be used to load
I need to write a java application which can merge docx files. Any suggestions?
In my Java application, I need to connect to the same host using SSL,

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.