jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JTextArea" Watch "JTextArea" New topic
Author

JTextArea

Felipe Walker
Ranch Hand

Joined: Sep 23, 2003
Posts: 41
I want to read the contents of the jtextarea and save it to a file. That part is easy but how do I save it so the data will not be one long line of information. I want to save teh date line by line like I typed it in the jtextarea.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Felipe,
Welcome to JavaRanch!
If when you type the information in, you let the JTextArea do automatic line wrapping, then the data is one long line, regardless of how it looks. On the other hand, if you press Enter at the end of each line, those should translate into '\n' characters which would be part of the data and should end up in the file.
The best thing to do, if you want the data to be in lines of a specific length in the file, would be to do the line-breaking yourself when you write the data out. There's a nice piece of code to do this in the Java Almanac online (a great resource -- browse around while you're there!)


[Jess in Action][AskingGoodQuestions]
 
Don't get me started about those stupid light bulbs.
 
subject: JTextArea
 
Similar Threads
Insertion in JTextArea
JTextArea + ActionListener
How to Save from JTextArea using JFileChooser as a TXT file.
JTextArea Problem
scrolling downwards in a jtextarea