Results 1 to 4 of 4
  1. #1
    luc@$ is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default New line in FileWriter

    Hi I'm creating a program and a problem appear but its so hard to solve:

    here area the problem

    I'm taking a string from a JtextArea1 for example:

    Java Code:
    Hi
    
    My house is yellow.
    
    I have a dog.

    and saving in a .txt

    Java Code:
            FileWriter writer;
        try {
          writer = new FileWriter("test.txt");
          String CA = jTextArea1.getText();
          writer.write(CA);
          writer.close();
        } catch (IOException e) {
          e.printStackTrace();
        }

    The final result in the .txt is:
    Java Code:
    Hi My house is yellow. I have a dog.

    I know I could use "/r/n" or System.getProperty( "line.separator") , however both need be used before the creation the JTextArea,

    How I could break the line only changing the code?

    Thanks for the help, I hope have been clear

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    If you use line breaks to separate the text in the JTextArea then those line breaks should be preserved when you call getText.

  3. #3
    luc@$ is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    If you use line breaks to separate the text in the JTextArea then those line breaks should be preserved when you call getText.
    Yes I know, i want know if have a way that separete the lines in the code because I call to many jTextArea and somes are writen by me so dont have how i use the /r/n

    thanks for your help junky

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

Similar Threads

  1. BufferedWriter, FileWriter
    By ladykrimson in forum New To Java
    Replies: 4
    Last Post: 12-06-2010, 03:35 AM
  2. issue with FileReader and FileWriter
    By Uma R in forum Advanced Java
    Replies: 6
    Last Post: 07-16-2010, 02:16 PM
  3. FileWriter doesn't write
    By superman5 in forum NetBeans
    Replies: 2
    Last Post: 07-30-2009, 06:46 AM
  4. JAva Filewriter
    By tommyyyy in forum New To Java
    Replies: 1
    Last Post: 03-28-2009, 01:51 PM
  5. New line or Carriage Return through FileWriter
    By johnt in forum New To Java
    Replies: 2
    Last Post: 05-20-2007, 10:13 PM

Posting Permissions

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