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

  • SEARCH
  • Home
  • 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 6644501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:10:29+00:00 2026-05-26T00:10:29+00:00

I need my Java app to read the config properties from a file and

  • 0

I need my Java app to read the config properties from a file and use them throughout the classes. I’m thinking of a separate class, that would return a map of property_key:property_value for each of the properties in the file. Then I would read the values from this map in other classes.
Maybe there are other, more commonly used options?

My properties file is simple and has about 15 entries.

  • 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-05-26T00:10:30+00:00Added an answer on May 26, 2026 at 12:10 am

    Just use java.util.Properties to load it. It implements Map already.
    You can load and get hold of the properties statically. Here’s an example assuming that you’ve a config.properties file in the com.example package:

    public final class Config {
    
        private static final Properties properties = new Properties();
    
        static {
            try {
                ClassLoader loader = Thread.currentThread().getContextClassLoader();
                properties.load(loader.getResourceAsStream("com/example/config.properties"));
            } catch (IOException e) {
                throw new ExceptionInInitializerError(e);
            }
        }
    
        public static String getSetting(String key) {
            return properties.getProperty(key);
        }
    
        // ...
    }
    

    Which can be used as

    String foo = Config.getSetting("foo");
    // ...
    

    You could if necessary abstract this implementation away by an interface and get the instance by an abstract factory.

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

Sidebar

Related Questions

I need to read a remote file using a java app, but the file
I know that you can use java.util.Properties to read Java properties files. See: Java
I need a disk backed Map structure to use in a Java app. It
I need to read XLS files from Java. For that purpose I start evaluating
I need a Java way to find a running Win process from which I
I have a XML schema that I will need to create Java classes for.
I need to write a Java Comparator class that compares Strings, however with one
I need to convert several Java classes to C#, but I have faced few
I need to calculate Math.exp() from java very frequently, is it possible to get
I'm trying to call a PostgreSQL stored procedure from a Java app; the procedure

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.