Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

getResourceAsStream Usage issue for absolute path

807600Nov 22 2007 — edited Nov 22 2007
Hi I m using the below function to get a InputStream which will be parsed using a parser but I m stuck up with an issue.
I m trying to get a xml file as Inputstream from getResourceAsStream method, but when i give path as
DEFAULT_FILE = "/home/wbiadmin/Tools/MonitoringTool/monitortool.xml"
InputStream is = getClass().getResourceAsStream(DEFAULT_FILE); it returns null,How to make it work by giving the above absolute path ???? I want to use absolute path.

when I keep file in same directory and give
DEFAULT_FILE = monitortool.xml"
InputStream is = getClass().getResourceAsStream(DEFAULT_FILE); it works,

Actually I have kept the path in classpath and I m getting the path from classpath , I m working on linux OS.Following is the function I m using in my program,



public InputStream getFileName()
{
String classPath = System.getProperty("java.class.path");


StringTokenizer tokenizer = new StringTokenizer(classPath,":",false);

String token = " " , DEFAULT_FILE = " ";

while( tokenizer.hasMoreTokens() )
{
token = tokenizer.nextToken();
System.out.println("\ntokens"+token);
if(token.endsWith("monitortool.xml"))
DEFAULT_FILE = token;
//when matches DEFAULT_FILE value is /home/wbiadmin/Tools/MonitoringTool/monitortool.xml
}


InputStream is = getClass().getResourceAsStream(DEFAULT_FILE);
return is;

}

Any kind of help regarding this will be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2007
Added on Nov 22 2007
2 comments
915 views