Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing file from jsp

 
Ambika Jain
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am unable to access a file in jsp. I am getting java.io.FileNotFoundException. How should I access file in jsp.

<%
BufferedReader br = new BufferedReader(new FileReader("data.txt"));
String line = br.readLine();
:
:
Thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a file you're shipping with your app, use
application.getResource(java.lang.String)
or
application.getResourceAsStream(java.lang.String)

The path must begin with a "/" and is interpreted as relative to the current context root.

If it's not part of the webapp, then use the FileReader as you were doing but pass it the full path to the file you want to read.
 
Ambika Jain
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben for the prompt reply. I am able to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!