Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JTextarea content writing into a file

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JTextarea content writing into 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.
    Last edited by ArpanSe; September 18th, 2011 at 07:24 AM. Reason: wrong conception


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: JTextarea content writing into a file

    Do you know that the notepad program treats the end of line and carriage return characters differently than the wordpad program. notepad will insert a small square when it doesn't understand the character n the file.
    Look at the file with wordpad. How does it look there?
    Or use the System.getProperty("line.separator") String to separate lines in the output file.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JTextarea content writing into a file

    This thread has been cross posted here:


    http://www.java-forums.org/awt-swing/48655-nee-help-writing-jtextarea-content-file.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. Want to Update Class File content
    By AlokPatil in forum Member Introductions
    Replies: 1
    Last Post: August 26th, 2011, 11:45 PM
  2. Changing Class File Content
    By xxcorrosionxx in forum Java Networking
    Replies: 2
    Last Post: January 18th, 2011, 07:46 AM
  3. reading content of the text file, splitting it into strings
    By Dodo in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: January 6th, 2011, 07:57 PM
  4. Facing problem with posting Excel file for download - Content in browser
    By ragz_82 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 9th, 2010, 08:28 AM
  5. quite small (make the changelog non-static, i.e. load its content from a file)
    By Abdallah in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 30th, 2009, 09:00 PM