wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Reading 2 Different Files into 1 JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading 2 Different Files into 1 JTextArea" Watch "Reading 2 Different Files into 1 JTextArea" New topic
Author

Reading 2 Different Files into 1 JTextArea

Brendan Thompson
Greenhorn

Joined: Apr 27, 2012
Posts: 21
I have a JTextArea that is supposed to display 2 different .java files within it. The problem I'm having is that the second file being read overwrites the first read file. I'm sure there's a simple fix, just can't seem to figure it out. Here's the code.




Here is the Applet class that initializes the above one:

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> The problem I'm having is that the second file being read overwrites the first read file.

you need to use append() after your first read()

some of the ways might be:
1) use the fileReader to read/append each line,
2) create another JTextArea

3) read the files in the reverse order
i.e. the second file read first, then store the text in a String
String temp = text.getText();
then text.read(..) which will be the first file over-writing the second file
then text.append(temp)
Brendan Thompson
Greenhorn

Joined: Apr 27, 2012
Posts: 21
Thanks! Solved my problem.
 
jQuery in Action, 2nd edition
 
subject: Reading 2 Different Files into 1 JTextArea
 
Similar Threads
A (hopefully) simple textbox question, continued
Getting Exception "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
How to read a file?
showing a text file from a jtree selection path
This method must return a result of type String