• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

using servlets on data from text files?

 
Ranch Hand
Posts: 61
  • 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.
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 help in
proceeding with the above functionality. hope u will guide me on how to proceed.
thanks in advance.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The biggest problem most people have when starting to work with files in servlets has to do with how to locate and open the file. If you expect to do something like:
FileInputStream fis = new FileInputStream("abcd.txt");
it won't work because that code depends on the "current directory."
Instead you must provide a complete path to the file or use one of the servlet methods that looks up a file path relative to the location of the web application.
You can use parameters in the web.xml file to pass in a complete path.
Bill
 
This will take every ounce of my mental strength! All for a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic