aspose file tools*
The moose likes Servlets and the fly likes servlets and text file data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets and text file data" Watch "servlets and text file data" New topic
Author

servlets and text file data

Sri Sar
Ranch Hand

Joined: Mar 25, 2004
Posts: 44
Hi,
i have two text files (abcd.txt and efgh.txt). text file abcd.txt contains names of districts in a country with their area values whereas the file efgh.txt contains the names of the same districts but with their population values. (the text files have only two columns: name of the district and either the area/population values)
now i want to write a servlet that extracts the 'area' values from abcd.txt and 'population' values from efgh.txt and calculates Density ie divides the area values by the population values and obtain the result.
since i am new to Servlets, i am in desperate need of some sort of sample code in proceeding with the above functionality.
thanks in advance.
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
Hi,

A good way to procedd is as follows. To load a file called 'conversion.dat' for the sake of argument, with a path of WEB-INF/currency relative to your application root, put the following in your web.xml (for tomcat at least!) file straight after your opening <webapp> label:



Now from within your servlet, create a File instance using this path:



Note the getServletContext() method must be called from within a servlet.

You can then treat this file in the normal way.

HTH

Jon
[ May 25, 2004: Message edited by: Jon Entwistle ]

SCJD, SCEA
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: servlets and text file data