Why does saving text from a jtextarea to a text file result in....?

one long string that includes square blocks when the new line should be?
Why can't I read normal text from a text file. It looks like i have to save it first for it to be read.
Also why is it that my application succesfully reads and displays the contents of a text file that i just saved but when i manually open that file I don't see it. All i can see is what the text that i manually entered into the text file.
I use a buffered reader so wondered if there was some caching but have no idea.

one long string that includes square blocks when the new line should be? If you use something like:
write(textArea.getText())
then "\n" will be written to the file as a newline string, but on a Windows platform the newline string is "\r\n".
You should be using the read(...) and write(...) methods of the JTextArea and the newline string will be handled correctly.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
class TextAreaLoad
     public static void main(String a[])
          final JTextArea edit = new JTextArea(5, 40);
          JButton read = new JButton("Read some.txt");
          read.addActionListener( new ActionListener()
               public void actionPerformed(ActionEvent e)
                    try
                         FileReader reader = new FileReader( "some.txt" );
                         BufferedReader br = new BufferedReader(reader);
                         edit.read( br, null );
                         br.close();
                         edit.requestFocus();
                    catch(Exception e2) { System.out.println(e2); }
          JButton write = new JButton("Write some.txt");
          write.addActionListener( new ActionListener()
               public void actionPerformed(ActionEvent e)
                    try
                         FileWriter writer = new FileWriter( "some.txt" );
                         BufferedWriter bw = new BufferedWriter( writer );
                         edit.write( bw );
                         bw.close();
                         edit.setText("");
                         edit.requestFocus();
                    catch(Exception e2) {}
          JFrame frame = new JFrame("TextArea Load");
          frame.getContentPane().add( new JScrollPane(edit), BorderLayout.NORTH );
          frame.getContentPane().add(read, BorderLayout.WEST);
          frame.getContentPane().add(write, BorderLayout.EAST);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo( null );
          frame.setVisible(true);
}

Similar Messages

  • Why does saving down from Illustrator 6 to older version sometimes not work?

    We have some users with CS6 and some with CS3 and 4, when a user tries to open an illustrator file from CS3 and 4 saved down from CS6 it will not open.  some files will open but most won't.

    Try running Firefox in [[Safe Mode]]. If it functions properly in that configuration, then one of your add-ons is the culprit.

  • Getting the text from a JTextArea...

    hi, I'm making a perfect calculator program and I'm trying to add a Note Pad function to it, I also want to hide that so the other interface can be used; I can get it hided and come again but I'm wondering how could I get the text from the JTextArea INCLUSIVE the enters that are made withing it, so:
    theString = jTextArea1.getText();only gives me the text and no enters; suggestions?

    I think I displayed it wrongTwo things to keep in mind...
    Certain Swing components will just ignore newlines, so you have to be careful where/how you're displaying your multiline text strings. Some components will display it all as one line, some will only display the top line, some will even show \n instead of doing the newline. It all just depends.
    And JTextArea does support word wrapping, so just because it looks like there's a newline, there may not be one.

  • Why does my Droid Maxx stop sending and receiving texts every afternoon?

    Why does my Droid Maxx stop sending and receiving texts every afternoon?

    Craigomal I am sorry to hear of the difficulties with texting! How long has this been going on?Can I get the zip code you are in so I can take a look at the area? Thanks in advance!
    BryanS_VZW
    Follow us on Twitter @VZWSupport
    If my response answered your question please click the "Correct Answer" button under my response. This ensures others can benefit from our conversation. Thanks in advance for your help with this!!

  • Why does the new operating system not delete the moved files from their original location - it seems like an enormous waste of space, time and effort to clean up every file once you've moved it

    Why does the new operating system not delete the moved files from their original locations - it seems like an enormous waste of space, time and effort to clean up every file once you've moved it - also, when transferring large amounts of files it becomes a very large problem remembering which files were transferred and which not.

    You're going to need to be more specific, as I'm not quite sure I understand what you're talking about.
    If you're referring to copying from an external hard drive or flash drive, and you want to actually move files rather than copy them, you can hold down the option key to force it to do a "move" rather than a "copy." This is not new behavior, though... the Mac OS has worked this way as long as I can recall (and I've been using it since 1984).
    If you're having a problem with trying to move files from one place to another on a single drive causing them to be copied instead, that is likely because of some permissions issue preventing you from actually being able to move them.

  • Guys...Why does my email from my iPhone show up as Gmail versus my email address @ Gmail?

    Guys...Why does my email from my iPhone show up as Gmail versus my email address @ Gmail?

    That's a question she may want to ask Samsung...

  • Why does my iphone 4s repeat the words I text?

    Why does my iphone 4s repeat the words I text?

    It was when I was typing the text.  I found the answer in the "More Like This" area on the side.  I swear my phone changes settings by itself!  :-)  Thanks!!!

  • Why does emoticons sent from my iphone 4s does not show on other phones

    why does emoticon sent from my phone does not show on other phones

    iOS emoticons are Unicode characters that need a certain set of glyphs to be able to be displayed—think of it as a missing font not displaying correctly. If the device you send them to doesn't have the "font", it can't show it.
    That's just the way it is.

  • Why does Bridge Need Illustrator to Save as PDF compatible file?

    1. Why does Bridge need Illustrator files to be saved as PDF files? "PDF Compatible File" ticked in the save menu.
    2. Why does saving with this info take so long, even on decent fast modern systems?
    3. Why does Bridge not consistently render the Illustrator files in FULL RESOLUTIONS, seemingly shooting for half resolution much of the time, and simply stopping at that?
    4. Why does "clicking" on the preview inside Bridge bring up the full resolution?
    5. How do I shortcut this process so that every file is previewed in Full RESOLUTION, instantly?
    What is the point of Bridge?  What's its reason for existence?
    First time user of Bridge.

    Since someone is bound to say that this should be asked in the Bridge section... it already is.  And has been referenced back over here.
    You can find it here:
    http://forums.adobe.com/message/5655632#5655632
    Answer wherever you see fit, if you're up to the task of dealing with someone attempting to have a broader view, perhaps also suffering from somewhat objective analysis that sometimes contains direct criticism of the way Adobe does things.

  • A problem with copying text from english pdf to a word file

    i have a problem with copying text from english pdf to a word file. the english text of pdf turns to be unknown signs when i copy them to word file .
    i illustrated what i mean in the picture i attached . note that i have adobe acrobat reader 9 . so please help cause i need to copy text to translate it .

    Is this an e-book? Does it allow for copying? It is possible that the pdf file is a scan of a book?

  • Why does Itunes say it can't find the original file for a particular song?

    why does Itunes say it can't find the original file for a particular song? and then asks if I want to locate it? I can't access a bunch of old song files. any new cds are available to me in itunes. all others are not accessible. how do i merge the new cd's with the old ones so that all the songs are playable in Itunes. thanks.

    sheri 0713 wrote:
    Of course, I have backed up to CD and/or external drive.
    I'm wondering if you're attempting to maintain your library on your external HDD? If iTunes has been directed to use a location on your external hard drive as your iTunes Music Folder location (you can check this in iTunes > Preferences > Advanced tab) you MUST ensure that the hard drive is connected to the computer and mounted in the Finder prior to launching iTunes. If it isn't, it can cause this error to appear. This is probably one of the most common reasons this error begins to appear.
    It seemed my purchased songs were the first to DISAPPEAR and I had to rebuy.(Nice scam in the bug?)
    So... why not restore them from your backup? If, for some reason, this wasn't an option, you could have also recovered them from any iPod or iPhone they were currently synced to (http://support.apple.com/kb/HT1848), or, you can also email iTunes Store support and request a "regrant," which is a once-per-account exception they might be able to offer you and allow you to download missing purchases again.
    I am now convinced this a HUGE BUG in 7.7.1. and possibly the previous version or two.
    I'm not so sure... I've never run across this particular error (my library is stored on my internal hard drive, but copied to an external for backup purposes with an application other than iTunes or Finder. I don't think Apple will provide acknowledgment to issues experienced only by very small numbers of people... I'm one of those, perhaps foolish, individuals who allows my computer to download updates immediately, rather than waiting for fear of problems, and again, I've never had this error.
    CG

  • Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick?

    Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick? I have to Relaunch the Finder to get it working again.
    Background / other symptoms:
    The Flash drive in question has been formatted HFS.
    I get no error messages, including on the Console, and no sound indicators.
    I can copy files, using the Finder, from a hard-drive to the usb flash drive with no problem.
    Finder copying on this stick works just fine on my other Mac.
    I can move files within another (FAT32-formatted) USB flash drive.
    The quirky USB HFS Flash drive works fine on my other Mac.
    Outside of the Finder, I can use mv just fine to move the files on the HFS flash drive.
    If the HFS-formatted Flash drive were faulty, I would at least expect some sort of error in the Console app, but perhaps not from the Finder.

    Why does the Yosemite Finder become unresponsive when moving a file within my USB Flash stick? I have to Relaunch the Finder to get it working again.
    Background / other symptoms:
    The Flash drive in question has been formatted HFS.
    I get no error messages, including on the Console, and no sound indicators.
    I can copy files, using the Finder, from a hard-drive to the usb flash drive with no problem.
    Finder copying on this stick works just fine on my other Mac.
    I can move files within another (FAT32-formatted) USB flash drive.
    The quirky USB HFS Flash drive works fine on my other Mac.
    Outside of the Finder, I can use mv just fine to move the files on the HFS flash drive.
    If the HFS-formatted Flash drive were faulty, I would at least expect some sort of error in the Console app, but perhaps not from the Finder.

  • A few days ago, I copied text from an iBook onto my text notebook. When I went to my kindle on my ipad and attempted to share a quote from it onto Facebook it pasted the previous quote from my iBook. I can't copy and paste anything except that quote. HELP

    A few days ago, I copied text from an iBook onto my text notebook. When I went to my kindle on my ipad and attempted to share a quote from it onto Facebook it pasted the previous quote from my iBook. I can't copy and paste anything except that quote. HELP

    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    etc.,
    someone may be able to help you (not necessarily this poster).
    a screen shot of your settings or of the image could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Whenever I send a text from my iphone 5 my text messages are appearing on other apple devices in the household.

    Whenever I send a text from my iphone 5 my text messages are appearing on other apple devices in the household. ie Iphone 4 and Ipod.
    How do I stop this occurring.

    You'll have to deselect your phone number on the other devices in Settings/Messages/Receive at/
    Check this post about iMessage:
    iMessage on iPad and iPhone Explained and De-Mystified

  • CR duplication when Copy/Pasting text from a JTextArea

    I have a typical scenario of having text in a JTextArea. When I select some of that text and try to paste it either to an external text editor or even in the same JTextArea, I am getting extra line spaces in the screen.
    For example, if I have the following text:
    <a id=1>
       <b/>
    </a>When I copy paste it, I get:
    <a id=1>
       <b/>
    </a>When I looked to see what characters were being used for the CR, I see "\r\n". This is the standard line.seperator for Windows OS which is fine. When I save this text to a file using the Java I/O libraries, it is fine (no extra lines). But when copy/pasting it prints extra lines.
    Has anyone had similar problems?

    Has anyone had similar problems? No. How are you doing the copy/paste? Did you write your own routines or are you using the default Actions. By default, when a Document is loaded it will convert the "\r\n" end of line string to "\n" and store the single character in the Document. When you use the getText(..) method the enod of line string will be expanded to "\r\n" on a Windows system, but this should not happen in a copy/paste operation. How do you add data to your text area?
    This section from the Swing tutorial on "Text Component Features" has a working example of using copy/paste:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

Maybe you are looking for

  • Is it even possible to dynamically apply view criteria in an ADF Web App?

    This is one of those situations where something that should take an hour ends up taking days. * I have a view. * The view has Bind Variables associated with it. * The view has View Criteria associated with it. * Each of the View Criteria use differen

  • Next Generation Jet Database?

    My company is already looking into the future beyond Exchange 2013 and we are interested in what storage engine\solution will be in place for the next generation of Exchange.  Some believe the Jet database needs to be seriously updated or another sto

  • Company code in deferred Transfer Tax

    Dear sir, When select multi company code in selection screen of Deferred transfer tax , the system will show the selected Company (to) to any document no. which is selected to transfer instead of the real company code of document. ASAP with thanks, k

  • PI 7.1 Multiple calls of BAPI

    Dear all, We have a file to RFC scenario; the file consists of multiple invoices which should be posted with BAPI_ACC_DOCUMENT_POST. As described in the Weblog of Michal Krawczyk (XI: IDoc bundling - the trick with the occurance change) I have export

  • Migration assistant for entourage to outlook?

    I used the Setup Assistant to transfer a Time Machine Backup of a macbook to my new macbook. Everything transferred fine except the Entourage database. I upgraded to Outlook 2011 for Mac. I have tried everything to no avail. Do you suppose I could us