• Post Reply Bookmark Topic Watch Topic
  • New Topic

using servlets on data from text files?

 
Yell Srik
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!