How to save the content of a JTextArea into a txt file?

Hi, I want to save the content of a JTextArea into a txt file line by line. Here is part of my code(catch IOException part is omitted):
String s = textArea.getText();
File file = new File("file.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(s);
bw.close();
But I found in the file all is binary code instead of text, any people can help me?
Thanks in advance

I can see text in the file now, but the problem is
when I write three lines in textarea, for example
111
222
333
then I open the txt file with notepad, it is
111222333
How to save them line by line? Use a PrintWriter. It lets you write lines (it's the same class as System.out).
http://java.sun.com/j2se/1.4/docs/api/java/io/PrintWriter.html

Similar Messages

  • How to save the value in Cedit control into a text file bu using measurement studio c++?

    Im using measurement studio c++ to create a application. How to save a randomly generated value which display in the CNumberEdit Control to a text file? how to do the coding part?

    You can use the CNiFile class to write the value out to a file. For example, create a new Measurement Studio C++ project and follow these steps:
    Add a CNiNumEdit to the dialog.
    Add a member variable for the CNiNumEdit called m_numEdit.
    Add a button to the dialog.
    Double-click the button to add a message handler for the button's BN_CLICKED message.
    Add the following code to the button's BN_CLICKED message handler:
    CNiFile file("C:\\Values.log", CFile::modeCreate | CFile::modeWrite | CFile::typeText);
    file << m_numEdit.Value << endl;
    file.Close();
    Run the application, edit the CNiNumEdit's value, and click the button. The value should be written to the Values.log
    file as specified in the code above.
    Hope this helps.
    - Elton

  • How to get the content of a website to a txt file via powershell

    Hello,
    I have a reporting server that creates a report to a URL, by running multiple .xsl files. I want to be able to gather the data in the URL and convert it to csv or txt file via powrshell.
    Again I want the data inside the URL, I've been playing around Net.Webclient but I'm not getting what I need.

    If you're using PowerShell 3.0 or later you can try using Invoke-WebRequest.
    This previous thread shows how you can download the content from the page.
    Without knowing what type of content (i.e. text vs images vs other objects) is on the page it's hard to say if this will work for you.
    Jason Warren
    @jaspnwarren
    jasonwarren.ca
    habaneroconsulting.com/Insights

  • How to Convert the content in BLOB field into a PDF file...

    Hi,
    I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
    I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
    Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
    I am using following example code to achieve my goal...
    Declare
    b blob;
    c clob;
    buffer VARCHAR2(32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER(38);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select blob_data into b from blobdata where id=1;
    c := blob2clob(b);
    file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
         amount := buffer_size;
         offset := 1;
         WHILE amount >= buffer_size
         LOOP
              DBMS_LOB.READ(c,amount,offset,buffer);
              -- buffer:=replace(buffer,chr(13),'');
              offset := offset + amount;
              UTL_FILE.PUT(file_handle,buffer);
              UTL_FILE.FFLUSH(file_handle);
         END LOOP;
         UTL_FILE.FCLOSE(file_handle);
    end;
    create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
    -- typecasts BLOB to CLOB (binary conversion)
    IS
    || Purpose : To Convert a BLOB File to CLOB File
    || INPUT : BLOB File
    || OUTPUT : CLOB File
    || History: MB V5.0 24.09.2007 RCMS00318572 Initial version
    ln_file_check NUMBER;
    ln_file_size NUMBER;
    v_text_file CLOB;
    v_binary_file BLOB;
    v_dest_offset INTEGER := 1;
    v_src_offset INTEGER := 1;
    v_warning INTEGER;
    lv_data CLOB;
    ln_length NUMBER;
    csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
    V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    BEGIN
    DBMS_LOB.createtemporary (v_text_file, TRUE);
    SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
    DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
    SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
    RETURN v_text_file;
    END;

    user755667 wrote:
    Hi,
    I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
    I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
    Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
    I am using following example code to achieve my goal...
    Declare
    b blob;
    c clob;
    buffer VARCHAR2(32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER(38);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select blob_data into b from blobdata where id=1;
    c := blob2clob(b);
    file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
         amount := buffer_size;
         offset := 1;
         WHILE amount >= buffer_size
         LOOP
              DBMS_LOB.READ(c,amount,offset,buffer);
              -- buffer:=replace(buffer,chr(13),'');
              offset := offset + amount;
              UTL_FILE.PUT(file_handle,buffer);
              UTL_FILE.FFLUSH(file_handle);
         END LOOP;
         UTL_FILE.FCLOSE(file_handle);
    end;
    create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
    -- typecasts BLOB to CLOB (binary conversion)
    IS
    || Purpose : To Convert a BLOB File to CLOB File
    || INPUT : BLOB File
    || OUTPUT : CLOB File
    || History: MB V5.0 24.09.2007 RCMS00318572 Initial version
    ln_file_check NUMBER;
    ln_file_size NUMBER;
    v_text_file CLOB;
    v_binary_file BLOB;
    v_dest_offset INTEGER := 1;
    v_src_offset INTEGER := 1;
    v_warning INTEGER;
    lv_data CLOB;
    ln_length NUMBER;
    csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
    V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    BEGIN
    DBMS_LOB.createtemporary (v_text_file, TRUE);
    SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
    DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
    SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
    RETURN v_text_file;
    END;I skimmed this and stopped reading when i saw the BLOB to CLOB function.
    You can't convert binary data into character based data.
    So very likely this is your problem.

  • How to get the content of a jTextArea?

    hi everyone
    can some body provide me with some help???
    I want to know how to get the content of a jTextArea
    it may be a String and i want to use that String to make some applications
    I've use this :
    String ch=jTextArea.getSelectedText()
    but i'm not sure it will work and i'm not sure it will take the text writen inside the jTextArea ... please help
    Thanks

    http://forum.java.sun.com/thread.jspa?threadID=778988&tstart=0

  • How to save the music received in Whatsapp into iPhone?

    How to save the music received in Whatsapp into iPhone?

    This is not an iphone-specific problem. The person who sent you the files should have known that you cannot save them from WhatsApp person  on any smart phone
    Best help is to Contact whatsup support for iOS at  [email protected]
    I understand you think this is a Apple problem but Apple Haven't created this App

  • How to save the contents of a file(not a text file)

    Hi all, I want to save the contents of a file(,png file, not a text file) as a field in a class. Shall I have it as a string or byte array or something?
    I have tried saving a file in a string but there were some problems with loading the file from a different platform. Following is my code.
            String string;
            try {
                StringBuffer sb = new StringBuffer(1024);
                char[] characterArray = new char[1024];
                BufferedReader br = new BufferedReader(new FileReader(file));
                while(br.read(characterArray) != -1){
                    sb.append(String.valueOf(characterArray));
                br.close();
                string= sb.toString();
            } catch (IOException ex) {
                ex.printStackTrace();
            }and I use the following code to recover the string back to a stream, and save that stream back to a time later.
        ByteArrayInputStream bais = new ByteArrayInputStream(map.getBytes());I realized that because this file is not a text file, the string could cause some problems. But anyone could tell me if I should use a byte array or someting? and how?
    Any help would be appreciated!
    Cheers,
    Jing

    You should use a byte array, and the binary streams (InputStream a& OutputStream). Never use Strings and Reader/Writer if you have binary data.
    Kaj

  • How to save the contents of one file into another file?

    Hai,
    i'm trying to save the contents of an existing file into a new file...
    for example.. if i'm having a ms word file namely ss.doc..
    now i want to save itz contents into another file namele dd.doc..
    How shall i do it..
    Can an one plzz explain me...
    senthil.

    Hi, Senthil.
    This Forum is not a general discussion forum.
    You don't believe that the InDesign SDK is a general purpose API. Do you?
    I think you must post issues like this where they belong, in this case in a Microsoft Word Forum.
    Best regards.
    Oscar.

  • I am thinking of buying a MacBook Air and am wondering how to get the content of my iPad into iTunes.

    I have iTunes on an old pc and am thinking of buying a MacBook Air. I am wondering how to get the content of my iPad on to the Mac as I know that sync only happens in one direction, from pc to device. I assume therefore that when I attach my pad to the new Mac it will sync to an empty iTunes and I will have lost all the content of my pad. I know I can restore purchases, but what about contacts, calendar, photos and music not purchased from apple. I have a fairly recent backup on a pen drive but it is a usb2 device and is formatted for a pc. Any advice would be appreciated.

    Do I copy my media library or from a backup.  I have a backup on my pc and on an external drive. This drive is usb2 and formatted for windows so I can't connect it to a MacBook Air to make the transfer.  Equally I don't think there is a way to connect the 2 computers via a cable ie usb2 one end and usb3 the other.  Will the computers talk to each other via wifi if I enable home share although I think this is only for music which still leaves contacts, mail etc.
    I am sorry to be such an ignoramus but any further help would be appreciated.

  • How to save the data of ABAP report into a notepad in desktop location???

    HI all,
    Can any one tell me how to transfer the data of ABAP report into a Notepad.
    Actually I have to schedule a ABAP report in background on daily basis and I want to transfer the
    whole record into Notepad.
    If any program is available for this..please clearify the relevent code for transferring.
    Thanks
    Rajeev

    declare a character type internal table.
    now move your data from it_data ( internal table with data ) into table itab.
    since you are running this report in background, you cannot save it to the desktop. Instead give any app server location
    data: itab(400) occurs 0 with header line.
    field-symbols: <fs1> type any.
    data: gv_file type rlgrap-filename default 'TEST.TXT'.
    data: gv_filepath type rlgrap-filename default <path>.
    LOOP AT it_data.
        DO 100 TIMES.
          ASSIGN COMPONENT sy-index OF STRUCTURE it_data TO <fs1>.
          IF sy-subrc = 0.
            CONCATENATE itab <fs1> INTO itab SEPARATED BY ' '.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
        SHIFT itab LEFT DELETING LEADING ' '.
        APPEND itab.
        CLEAR itab.
      ENDLOOP.
      concatenate gv_filepath '/' gv_file into gv_file.
      OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc = 0.
        LOOP AT itab.
          TRANSFER itab TO gv_file.
        ENDLOOP.
        CLOSE DATASET gv_file.
      ENDIF.

  • With JDIC WebBrowser, how to save the content as an image ?

    I wonder if there is a way to save the WebBrowser's content (Html page with graphics) into a *.png image file ? The html page may span several screens, if I do a screen shot, I can only get the top part which I can see, but will miss the off screen contents. What I mean is : if the page is 900(W) x 3500(H) pixels, how to ask my java program to take a screen shot which can get the whole image of the WebBrowser content, including those off the bottom of the screen ?
    I was able to do this with the following method for JComponent
      public static BufferedImage Get_JComponent_Image(JComponent J_Component,Rectangle region) throws IOException   // Create a BufferedImage for Swing components. All or part of the component can be captured to an image.
       /* @param J_Component Swing component to create image from
        * @param region The region of the component to be captured to an image
        * @return image the image for the given region
        * @exception IOException if an error occurs during writing
        boolean opaqueValue=J_Component.isOpaque();
        J_Component.setOpaque(true);
        BufferedImage image=new BufferedImage(region==null?J_Component.getWidth():region.width,region==null?J_Component.getHeight():region.height,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d=image.createGraphics();
        g2d.setClip(region);
        J_Component.paint(g2d);
        g2d.dispose();
        J_Component.setOpaque(opaqueValue);
        return image;
      }So I tried to modify this method to work for Component (since WebBrowser is a sub-class of it), I got black screen with the following modified method :
      public static BufferedImage Get_Component_Image(Component A_Component,Rectangle region) throws IOException   // Create a BufferedImage for Swing components. All or part of the component can be captured to an image.
       /* @param A_Component AWT component to create image from
        * @param region The region of the component to be captured to an image
        * @return image the image for the given region
        * @exception IOException if an error occurs during writing
        boolean opaqueValue=A_Component.isOpaque();
        Out("opaqueValue="+opaqueValue);
    //    A_Component.setOpaque(true);
        BufferedImage image=new BufferedImage(region==null?A_Component.getWidth():region.width,region==null?A_Component.getHeight():region.height,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d=image.createGraphics();
        g2d.setClip(region);
        A_Component.paint(g2d);
        g2d.dispose();
    //    A_Component.setOpaque(opaqueValue);
        return image;
      }Can anyone tell me what I did wrong ? Thanks.
    Frank

    Hi,
    Even im looking for the same thing. I tried createImage on the panel but its giving me a blank screenshot, which i presume does not works on the embedded IE area and gives the blank screenshot of the jPanel behind it.
    Kindly post any solution you might have come up with.
    Thanx

  • Really need help... How to print the 'content' of a JTextArea?

    Hello, i'm currently developping a HTML Editor in java but i've got a problem with printing job... Does anyone know a simple code to print the content of a textarea by clicking on a button?
    for instance:
    JTextarea textarea = new JTextArea();
    JButton print = new JButton ();
    file_menu.add(print) ;
    print.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent event)
    ////----> what could i put here to print the content of my textarea named 'textarea' ?
    I've searched on the web but i didn't find it...
    Thanks very much for your help...
    Sebastien Roupin

    thank you very much for your help... i'm checking this samples...
    Sebastien Roupin

  • How to transfer the content in a StringBuffer into a InputStream

    I need append the comment to the buttom of each file. I read the file into the stringbuffer first, appending the comments. After completed, how can I send the content in the StringBuffer back into a InputString in order to continue with some other file manipulation?
    I saw a method StringBuffer.toString(), but nothing to transfer back to InputString
    Thank you in advance

    How aboutnew StringReader(sb.toString());Since you are working with text data, you should be working with Readers instead of InputStreams.
    (And if you are appending data to a file, wouldn't it be more effective to just use the version of FileWriter that allows you to append the data, instead of reading the whole file and writing the updated file back?)

  • How to save the image after converting it into 64RGB

    Hello every one,
    I am trying to save the output image of 64RGB on my computer. Is this possible? I had a go and could not do it. Can some one look at my code please. 
    Regards,
    Lazer
    Solved!
    Go to Solution.
    Attachments:
    Save 64 RGB image.vi ‏91 KB
    1800s.jpg ‏8 KB

    Have a look at the following:
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • How to write the org.w3c.dom.Document  into an XML file.

    The file doesn't not exist. I have a class to form an XML Document object with giving parameters. And then how to write this Document object to an specialitied
    file?

    The easiest way is to use a Transformer to do an default transform of the document from a DOMSource to a StreamResult.
    something like
             TransformerFactory tf = TransformerFactory.newInstance();
             tf.setAttribute("indent-number", new Integer(4));
             Transformer t = tf.newTransformer();
             t.setOutputProperty(OutputKeys.INDENT, "yes");
             t.setOutputProperty(OutputKeys.METHOD, "xml");
             t.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");
             t.transform(new DOMSource(yourDOMDocument), new StreamResult(new OutputStreamWriter(yourFileOutputStream)));

Maybe you are looking for

  • After installing ios 5 on my iPod touch I can no longer get the voice command up.

    I know the home button still works but for some reason voice command just won't come up. Help??

  • HP LaserJet P1102w prints 1/2 inch too far down on the page

    When I print with this printer using Word it starts printing about half an inch down on the page. I've tried resetting it to factory defaults but it still fails on me. Any help would be appreciated. This question was solved. View Solution.

  • Power G3/LCD Display Upgrade?

    I have a Blue and White Power G3 and would like to upgrade to a 22" LCD display. Are there any limitations with OS 9.2.2 and the ATI Rage 128 card that I should be aware of when making a selection? I don't want to spend any more than I need to and so

  • Headless Mac Mini feed CDs

    Can I somehow use disc sharing on my MBP to feed CD's to iTunes on a headless Mac Mini? And better yet, can I do it over the internet? I've set my Uncle up with a Mac Mini running his music via iTunes, using an iPad and "Remote" to control it. It's o

  • Upgraded itunes, ipod crashed and can't reinstall.

    hi, i upgraded to the new version of itunes yesterday, and then itunes wouldn't recognize my ipod (classic, 160 GB). i kept getting the error message "itunes can't read the contents of rachel's ipod." (http://forums.ilounge.com/windows-ipod-discussio