users@glassfish.java.net

Re: reading text file in servlet

From: <glassfish_at_javadesktop.org>
Date: Thu, 12 Mar 2009 21:01:12 PDT

Jan,

Thanks for the reply. While I understand what is in the blog, I don't think I know how to apply it to my case. May be I am not that knowledgable on the relationship between URI and file. Let me put it in a more specific way:

I have this in my sun-web.xml
<sun-web-app>
  <context-root>/testing-war</context-root>
  <property name="alternatedocroot_1" value="from=/testing/* dir=C:/Dev/java/NetBeans_projects"/>
.....

What should I code, in my servlet's doGet() method so that I can open the text file and read the data? And where in absolute path should I put my text file?

I've tried new File(new URI("/myFile.txt")) but failed with "URI is not file:". I've tried new File(new URI("file:/myFile.txt")) but it looks for the file in c:\myFile.txt, not in the "dir" in my property. I've tried new File(new URI("file:myFile.txt")) but failed with "URI not hierarchical ". Please help.
[Message sent by forum member 'senderj' (senderj)]

http://forums.java.net/jive/thread.jspa?messageID=336774