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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:28:24+00:00 2026-05-25T22:28:24+00:00

I am trying to implement a method that when called, get a string from

  • 0

I am trying to implement a method that when called, get a string from a particular resource in the jar that the class is loaded from.

For example:

import mypath.myclass; //from a jar
String result = gitid.getGitId(myclass.class);

On the backed I am currently using:

InputStream is = null;
BufferedReader br = null;
String line;
is = c.getResourceAsStream("/com/file.text");

The problem is I keep getting the same resource for no matter what class I give it.

I have also tried:

is = c.getClassLoader().getResourceAsStream("/com/file.text");

This fails completely.

Any suggestions would be much appreciated.

Also,what is the difference between calling getResourceAsStream from the class loader vs the class?

  • 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-25T22:28:25+00:00Added an answer on May 25, 2026 at 10:28 pm

    The Class.getResourceAsStream() gets a ClassLoader instance, pretty much the same you get from Class.getClassLoader() call.

    What you could do, is get the URL for a given class and replace class resource path your path of your file. for example, the following code will return resource from the same jar:

      Class c = String.class;
      URL u = c.getResource('/' + c.getName().replace('.', '/') + ".class");
      String s = u.toString();
      URL url = new URL(s.substring(0, s.indexOf('!')) + "!/META-INF/MANIFEST.MF");
      InputStream is = url.openStream();
    

    You’ll have to handle not jarred class folders separately.

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

Sidebar

Related Questions

I'm trying to implement a class in C# with a method that intercepts the
I'm trying to implement method Find that searches the database. I forgot to mention
I'm trying to implement a simple method to read new lines from a log
I'm trying to implement a iGoogle like dashboard interface using widgets that get their
If my class SomeType has a method that returns a element from the map
I'm trying to serialize a class that inherits from a base class that implements
I'm trying to sub-class db.Property and override the set method to implement stuff like
Ive a Listner class called TopicS Im trying to call it from a gui
I am trying to implement my own authentication method for AuthKit and am trying
I would like to implement the method User.calculate_hashed_password . I'm trying to use the

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.