Opening a txt file in java

thomas_anderson
thomas_anderson used Ask the Experts™
on
I'm begining in the jsp/servlet programing, I just estn to know how to get a txt file, open the file, and show it in a jsp page.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
THANKS
Commented:
will you be retrieving the text file from the server???? if so, here's a sample code....

<%@ page import="java.io.*" %>
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>

<%
  String myTextFile = "C:\\myTextFile.txt";
  BufferedReader br = new BufferedReader(new FileReader(myTextFile));
%>
<html>
<head>
<title>Text File Reader</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>


<body bgcolor="#FFFFFF" text="#000000">
TextFile Contents:<br>
<%
  String output = br.readLine();
  while (output != null) {
%>
    <font face="arial, san-serif">
      <B>
        <%=output%><br>
      </B>
    </font>
<%
    output = br.readLine();
  }
%>
</body>
</html>

Commented:
and don't forget to close br once you're done with it.

vemul
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Commented:
hehehehe.... sorry i forgot.... =)
thomas_anderson:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for spoj

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer

Commented:
=)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial