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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:21:16+00:00 2026-05-10T23:21:16+00:00

I need to read a properties files that’s buried in my package structure in

  • 0

I need to read a properties files that’s buried in my package structure in com.al.common.email.templates.

I’ve tried everything and I can’t figure it out.

In the end, my code will be running in a servlet container, but I don’t want to depend on the container for anything. I write JUnit test cases and it needs to work in both.

  • 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. 2026-05-10T23:21:17+00:00Added an answer on May 10, 2026 at 11:21 pm

    When loading the Properties from a Class in the package com.al.common.email.templates you can use

    Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream('foo.properties'); prop.load(in); in.close(); 

    (Add all the necessary exception handling).

    If your class is not in that package, you need to aquire the InputStream slightly differently:

    InputStream in =   getClass().getResourceAsStream('/com/al/common/email/templates/foo.properties'); 

    Relative paths (those without a leading ‘/’) in getResource()/getResourceAsStream() mean that the resource will be searched relative to the directory which represents the package the class is in.

    Using java.lang.String.class.getResource('foo.txt') would search for the (inexistent) file /java/lang/String/foo.txt on the classpath.

    Using an absolute path (one that starts with ‘/’) means that the current package is ignored.

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

Sidebar

Related Questions

I need to delete a directory that contains read-only files. Which approach is better:
I know that you can use java.util.Properties to read Java properties files. See: Java
I need to read from a variety of different text files (I've some delimited
I need to read selected files, matching on the file name, from a remote
I need to read smallish (few MB at the most, UTF-8 encoded) XML files,
I need to read some large files (from 50k to 100k lines), structured in
I need to write a web-aplication that connects to database and reads connections properties
I have 15 1-second wav files, that need to play one every second, for
I'm attempting to write a method that will read a properties file using Class.getResource(),
I need my Java app to read the config properties from a file and

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.