Results 1 to 2 of 2
  1. #1
    ArpanSe is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default Nee help in writing the JTextarea content to a file

    Hi,I am having one problem while writing the content of JTextarea to a file.e.g if my textarea contains the following lines:
    line1: A
    line2: B
    line3:\n
    line4:\n
    if I am writing using "BufferedWriter wr=new BufferedWriter(new FileWriter(file));
    wr.write(textarea.getText());" some additional junk characters are added in to the file which can be seen if I open the file in notepad.
    The second approach which I used was,if the textarea content I am splitting line by line with the readline() method and writing line by line into the file, such as "BufferedReader reader = new BufferedReader(new StringReader(
    textArea.getText()));

    out1 = new PrintWriter(file);

    while ((l_stSingleLine = reader.readLine()) != null ) {

    out1.println(l_stSingleLine);
    out1.flush();
    }
    }"
    One extra "\n" is added at last i.e after the write operation file contains five lines(Using the second approach the junk characters are not coming).Please help me in writing the file with exact content.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

Similar Threads

  1. Writing To A TextFile From A JTextArea
    By anthropamorphic in forum AWT / Swing
    Replies: 13
    Last Post: 09-11-2011, 03:19 AM
  2. Replies: 10
    Last Post: 05-24-2010, 08:25 PM
  3. Update content on a JTextArea.
    By Masochist in forum New To Java
    Replies: 7
    Last Post: 05-13-2010, 10:18 PM
  4. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  5. Jtextarea Content Display Problem
    By REVANSIDDHA in forum Advanced Java
    Replies: 1
    Last Post: 03-31-2009, 06:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •