Reading .txt files and put it into a TextArea

Hi all,

I got a problem! I have to make something like a messenger.

I want to put the written text into a .txt file, after that I have to get the text out of the .txt file and put in into a TextArea.

I would ike it to to that like this:

">User 1

Hello!

>User 2

Hi!

"

Now here are my questions:

1: What is the moet easy way to do this ?

2: How could i put Enters into a .txt file with Java ?

3: How could i read all the text from the .txt file and put it into a TextArea WITH ENTERS ?

Thanks for your help!

Greetings, Jasper Kouwenberg

[636 byte] By [Jasper91a] at [2007-11-26 13:48:54]
# 1
[url= http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html#read(java.io.Reader,%20java.lang.Object)]JTextComponent[/url] has a read() method. Never used it butthat might do what you need.
TuringPesta at 2007-7-8 1:25:09 > top of Java-index,Java Essentials,Java Programming...
# 2

use JTextArea.read(new FileReader(fileName))

for reading.

and JTextArea.write(new FileWriter(fileName))

for writing.

The enters should be ok if the user press enter and adds a new line ("\n") to the text area component.

It will save the enter in the text file and load it correctly back to the text area.

If you want to add enter programmatically just add "\n" string to the text area component.

Rodney_McKaya at 2007-7-8 1:25:09 > top of Java-index,Java Essentials,Java Programming...