This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a web application that utilizes a context listener to instantiate an object that parses data from a raw text file and inserts it into a data structure. The reference to this data structure object is then stored in a context attribute.
The deployment problem that I am having is that when the context is initialized, my application cannot find the text file. Here's my code:
From the DD:
The listener class:
The actual file reader class:
I placed the rates directory directly under the application directory. Based on my code, is this where it should be or am I pointing to something else? Any tips would be appreciated. [ August 08, 2005: Message edited by: Jon Cone ]
I think you should use real path to read file as above post mentioned.
In addition, you can use follow method if your file is located under document root of your web app.
ServletContext java.io.InputStream getResourceAsStream(java.lang.String path) Although the path should be start with "/" , it is not absolute path. It is relative to your document root of your web app.
Sun(java)-SCJA SCJP SCWCD SCBCD SCDJWS SCEA<br />Sun(solaris)-SCSA SCSN<br />IBM-486 Object-Oriented Analysis and Design with UML Test <br />IBM Certified System Administrator - WebSphere Application Server Network Deployment V6.0<br />Oracle-OCA
I think you should use getResourceAsStream instead of your own method. Because this method uses ClassLoader to get stream, if your application is packaged as a war, this method will work very well while yours may not work