-
How-to read a text file and display it in a Text-area ...
Hi all, I have a servlet (written in java) that should read a TEXT file, put
all the content of the text file in a variable and then display it in the
text area like this:
<td><textarea rows=\"11\" cols=\"131\">" + TEXT + "</textarea></td>\n"
Now the problem is that I can only read a line from the text file:
FileReader fr = new FileReader(doc_path + doc_name + doc_ext);
BufferedReader myInput = new BufferedReader(fr);
TEXT = myInput.readLine();
HOW could I display the whole TEXT of the file ?
Thank in advance,
Gabriele
-
Re: How-to read a text file and display it in a Text-area ...
Hi Gabriele,
the BufferedReader.readLine() method will return a line from the file. When
the end of the input has been reached, it returns a null. To read the whole
file, use the following loop:
String tmp;
while ((tmp = br.readLine()) != null)
{
TEXT += tmp;
}
out.println("<td><textarea rows=11 cols=131>" + TEXT + "\n");
That should do it.
V
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks