• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

servlets and text file data

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
I think she's lovely. It's this tiny ad that called her crazy:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic