GeeCON Prague 2014*
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


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading 2 Different Files into 1 JTextArea