• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea

 
Felipe Walker
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic