Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading 2 Different Files into 1 JTextArea

 
Brendan Thompson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Solved my problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic