File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes reading text files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "reading text files" Watch "reading text files" New topic

reading text files

Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
I have to read from a text file from java helper class which is under tomcat's web-inf directory. I am not sure how to load the file from the java class?
right now

ReaderClass rc = new ReaderClass("C:\\myClass\\test.txt");

but when I keept hte class file inside tomcat this will NOT work. any suggestions?

Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
You can pack your helper classes and keep into tomcat's lib directory.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
I think you need code it like this

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
Thanks for your reply.

From a java class file how can I call a servlet? what is config in the above example? Sorry I am just confused and new to servlet concept.

BufferedReader infile = new BufferedReader(new FileReader(config.getServletContext().getRealPath("path_to_your_file")));?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

If the file is in your webapp, you can use getResource or getResourceAsStream getResource(java.lang.String)

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: reading text files
It's not a secret anymore!