Skip to main content

[webtier] Re: reading text file in servlet

1 reply [Last post]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jan Luehe

On 03/12/09 09:01 PM, wrote:
> 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
> /testing-war
> .....
> 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.

In your servlet, you can acquire a URL to the resource that is stored in
alternate docroot, as follows:


This will return a URL to this resource:


Hope this helps.



> [Message sent by forum member 'senderj' (senderj)]
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail: