Displaying the contents of a text file into a Text Area...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Displaying the contents of a text file into a Text Area...

Hybrid View

  1. #1
    Gabriele Guest

    Displaying the contents of a text file into 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

  2. #2
    mike m Guest

    Re: Displaying the contents of a text file into a Text Area...


    do something like this

    StringBuffer buff = new StringBuffer();
    String line;

    while ((line = buff_read.readLine()) != null)
    { buff.append(line);
    }

    this will read the whole file... then

    TEXT = buff.toString();

    give it a try

    "Gabriele" <ggdublin@yahoo.it> wrote:
    >
    >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 + "


  3. #3
    Andrew Guest

    Re: Displaying the contents of a text file into a Text Area...


    Read the file into a StringBuffer:

    FileReader fr = new FileReader(doc_path + doc_name + doc_ext);
    BufferedReader myInput = new BufferedReader(fr);

    String s;
    StringBuffer b = new StringBuffer();
    while ((s = myInput.readLine()) != null) {
    b.append(s);
    b.append("\n");
    }

    TEXT = b.toString();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center