This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Inpust stream path issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Inpust stream path issue" Watch "Inpust stream path issue" New topic
Author

Inpust stream path issue

Ayyappan Selvaraj
Ranch Hand

Joined: Sep 20, 2004
Posts: 63
I try to get the contnets of a file in my class. I use the following code snippet.

But I find that the input streams 'rules' and 'is' are null. I guess that the path of the xml file is not being recongnized.

Please help...


String path =(String)req.getRealPath("/WEB-INF/").replace('\\','/');
String outPath=path.concat("/validator-rules.xml");
InputStream rules = Thread.currentThread().getContextClassLoader().getResourceAsStream(outPath);
final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/WEB-INF/validation.xml");
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

That's servlet code. In web applications, an easier and fool proof way to get handles to an input stream is to use the ServletContext's getResourceAsStream("path") method where path should begin with "/". The "/" represents the servlet's context.

Thus



ram.
Ayyappan Selvaraj
Ranch Hand

Joined: Sep 20, 2004
Posts: 63
Ram,

its working now. Thanks you very much.
and you know Struts?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Inpust stream path issue
 
Similar Threads
Open a PDF fie inside a jar
getResourceAsStream(path) Path issue during validation
Cannot load WDSL?
Accessing files under WEB-INF
reading a properties file