hi des xu,
Thefollowing code might be easier to follow, it reads a file named 'newsfile.txt' in the same directory as this JSP file, and puts the content into a string named 'news'.
<HR>
<PRE>
<%@ page import = "java.io.*, java.util.*" %>
<%
// Read in the text file newsfile.txt
ServletContext context = getServletContext();
String file = (context.getRealPath("/newsfile.txt"));
String s, news = new String();
try {
DataInputStream in =
new DataInputStream(
new BufferedInputStream(
new FileInputStream(file)));
while((s = in.readLine())!= null) {
news += s + "\n";
}
in.close();
} catch(Exception e) {
System.out.println("NewsFile read: " +e);
}
%>
(Surround next line with HTML PRE, or use HTML tags in text file!)
<%=news%>
</PRE>
Regards,
Tirumalarao
Developer TechnicalSupport,
Sun MicroSystem,India.