File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


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

Joined: Jul 08, 2003
Posts: 24199

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]
subject: JTextArea
It's not a secret anymore!