JAva.

Discussion in 'Programmer's Corner' started by gusmas, Oct 21, 2009.

  1. gusmas

    Thread Starter Active Member

    Sep 27, 2008
    239
    0
    i need to write from a jtextarea to a text file, but i have no idea how i am going to di it, any ideas
     
  2. davebee

    Well-Known Member

    Oct 22, 2008
    539
    46
    A JTextArea inherits the method "String getText()" from JTextComponent, so can you open a file, do

    String mytext = myJTextArea.getText();

    then write that string to the file, like

    out.write(mytext);
     
  3. gusmas

    Thread Starter Active Member

    Sep 27, 2008
    239
    0
    Cool thx that worked, bt when i make a couple of lines beneath one another in the jtextfield, it saves all the text next to each other and the new liner have a funny symbol
     
  4. davebee

    Well-Known Member

    Oct 22, 2008
    539
    46
    The JTextArea is fairly simple in its formatting. It will break text for display on word boundaries, but it does not embed CR/LF characters into the text.

    So on extracting the text, you get exactly what had been initially written in.

    If you want line formatting from a JTextArea object, you'll have to do it yourself somehow.
     
  5. aadhar

    New Member

    Oct 21, 2009
    1
    0
    String mytext = myJTextArea.getText();
    Then
    out.write(mytext);
     
    Last edited by a moderator: Oct 26, 2009
Loading...