• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading text files

 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

thanks,
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can pack your helper classes and keep into tomcat's lib directory.
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need code it like this
 
Vanitha Sugumaran
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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")));?

thanks,
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the file is in your webapp, you can use getResource or getResourceAsStream
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html# getResource(java.lang.String)
 
reply
    Bookmark Topic Watch Topic
  • New Topic