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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:58:47+00:00 2026-05-15T05:58:47+00:00

I have a words.txt file that I have put in a particular java package

  • 0

I have a words.txt file that I have put in a particular java package and would need to read it from that same location. I do not control the deployment, so I don’t know where the packages will be deployed.

Example location: com/example/files/words.txt .

I know how to use the ResourceBundle class to read properties file from the package hierarchy rather than a relative/absolute path. like ResourceBundle.getBundle(com.example.files.words) Is there something similar for general files so that I can read it from the package hierarchy rather than some absolute/relative path?

  • 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-15T05:58:47+00:00Added an answer on May 15, 2026 at 5:58 am

    You can use the getResourceAsStream() method (defined at class Class) to retrieve resources from the class-path. If class WordReader is located in package com.example then the path to the resource file should be files/words.txt

    package com.example;
    
    public class WordReader {
    
       public void readWords() {
         InputStream is = getClass().getResourceAsStream("files/words.txt");
         StringBuilder sb = new StringBuilder();
         for(Scanner sc = new Scanner(is); sc.hasNext(); )  
             sb.append(sc.nextLine()).append('\n');
    
         String content = sb.toString();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have quite a large list of words in a txt file and I'm
I have an unsorted dictionary file named dict.txt. I have managed to put the
I have hundreds of .doc files with text that I need put on web
I have an algorithm that generates strings based on a list of input words.
I have rough ideas - like dealing with singular/plural, two or more words/phrases that
Could anybody explain in plain words how Cloud computing works? I have read the
We used to have a search, that checks two columns for some words. Both
I have an word document which I want to convert to text (.txt) file
i have a txt file with a list of country's. For my form i
We have 5mb of typical text (just plain words). We have 1000 words/phrases to

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.