I am curious what the most efficient way is to read a text file (do not worry about size, it is reasonably small so java.io is fine) and then dump its contents into a JTextArea for display.
E.g. can I somehow consume the entire file in a single string and then use JTextArea.setText to display it or should I read line by line or byte arrays and populate them into a StringBuffer and then set the text area to that?
Thanks
You can use
JTextComponent.read(Reader, Object)and pass it aFileReader. Just do this:Java 7 — try-resource block
Java 6 — try-finally block