How can I view a text file in a JTextArea without any user input?

John Zukowski

Assuming you know what text file to read already, just read the file into a StringWriter. Once you have everything read, get the String from the StringWriter with toString() and call setText() on the JTextArea with the contents. Something like the following code:

FileInputStream input = new FileInputStream(...);
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringWriter writer = new StringWriter();
PrinterWriter out = new PrintWriter(writer);
String line;
while ((line = reader.readLine()) != null)  {

In the case of an applet, the FileInputStream line would be something like a getInputStream() from a URLConnection.