// // Example2.txt - another trivial program... // Compile: javac Example2.java // Run: have example2.txt in current directory and // java Example2 example2.txt // It opens plain.txt and displays it. // Author: Gaspar Sinai Tokyo 2002-02-04 // import javax.swing.*; import java.awt.*; import java.io.*; class Example2 { public static void main (String args[]) { if (args.length ==0) { System.err.println ("usage: Example2 filename"); System.exit (0); } JFrame frame = new JFrame(); try { frame.setTitle ("java " + System.getProperty("java.version")); } catch (Exception e) { } JTextArea textArea = new JTextArea(); try { BufferedReader reader = new BufferedReader ( new InputStreamReader (new FileInputStream (new File (args[0])), "UTF8")); String str; while ((str=reader.readLine()) != null) { textArea.append (str); textArea.append ("\n"); } } catch (IOException e) { } catch (Exception e) { e.printStackTrace(); System.exit (0); } frame.getContentPane().add (textArea); frame.pack(); frame.setSize(300, 100); frame.show(); } }