0

Hi All

I have written JSP to read a text file(Text file and JSP are in same location) and display the data. when I am trying to run the JSP it is displaying "Error:Null".

here is my code

<% 

try{
java.net.URL url =config.getServletContext().getResource("/textfile.txt");BufferedReader buffreader =new BufferedReader(new InputStreamReader(url.openStream()));
String strLine;
while ((strLine = buffreader.readLine()) != null)  
{
	out.println(strLine);
}
	}catch (Exception e){
		System.err.println("Error: " + e.getMessage());
		}
%>

Thanks in Advance.

Edited by __avd: Added [code]..[/code] tags.

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by javaAddict
0

Try to print the stack trace in order to get a better understanding:

<% 

try{
java.net.URL url =config.getServletContext().getResource("/textfile.txt");BufferedReader buffreader =new BufferedReader(new InputStreamReader(url.openStream()));
String strLine;
while ((strLine = buffreader.readLine()) != null)  
{
	out.println(strLine);
}
	}catch (Exception e){
                e.printStackTrace(); // HERE
		System.err.println("Error: " + e.getMessage());
		}
%>

You probably get a NullPointerException somewhere

Edited by javaAddict: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.