getResourceAsStream Usage issue for absolute path
807600Nov 22 2007 — edited Nov 22 2007Hi 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.