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
You can use JTextComponent.read(Reader, Object) and pass it a FileReader. Just do this:
Java 7 -- try-resource block
try (FileReader reader = new FileReader("myfile.txt")) {
textArea.read(reader, null);
}
Java 6 -- try-finally block
FileReader reader = null;
try {
reader = new FileReader("myfile.txt");
textArea.read(reader, null);
} finally {
if (reader != null) {
reader.close();
}
}