File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes getInputStream - relative path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "getInputStream - relative path" Watch "getInputStream - relative path" New topic
Author

getInputStream - relative path

Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Hello All,

I have a jar file (GLUE-STD.jar) which has a class JARLoader in package electric.xml.io.mapping

The JARLoader class has following code

inputstream = ClassLoaders.getInputStream("file:/".concat(String.valueOf(String.valueOf(s))));

Basically above code reads mappings.jar which is currently located in c:\

I need to modify the above code in such a way that the JARLoader class should look for mappings.jar in the same folder that has GLUE-STD.jar using relative path not physical path so that app finds the jar file while running on Windows as well as Linux environment.

Really appreciate any suggestions.

Thanks
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
put your folder in the classpath. Use the following code.



Hope this helps.


Amit Tank
Linked In
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Amit:


(The getClass() method is not static so the above code will not compile. I think this was a typo but just wanted to point out.)

There is a subtle difference between using getResourceAsStream() in java.lang.Class and the one in java.lang.ClassLoader.
The former method expects the requested resource to be present in the classpath in the directory structure resembling the package name of the class. So, if your class name is foo.bar.MyClass then the requested resource must be present under foo/bar/ under any of the directories in the classpath.
The method in the ClassLoader expects the resource to be present directly in the classpath.


apigee, a better way to API!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What are you going to do with the InputStream and why? I have the vague feeling that there might be a better way to solve the problem you are trying to solve...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getInputStream - relative path
 
Similar Threads
Help with JarURLConnection
Executing my .java in package
Jars inside one jar?
same class in two jar files
my JarLoader breaks when replacing the jar file