File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Reading files into JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading files into JTextArea" Watch "Reading files into JTextArea" New topic
Author

Reading files into JTextArea

Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
I'm trying to read multiple text files into a JTextArea. I'm currently selecting them via JFileChooser dialog, which returns the selectedFiles back as a File[]. When I try and output the files contents it only displays the last file read in.

Here's my code:

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
You could write the sequence of files into a temp file and read it into the text area. Or, you could make a PlainDocument, write the files into it with the insertString method and set the document in the text area.
Or, you could use the append method and write as you read the files:
Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
For large text file append goes really slow. I think I'll try merging the files into one large file and initializing the JTextArea with that. Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading files into JTextArea