import java.applet.*; import java.awt.*; import java.io.*; import java.net.*; /* */ public class ReadFile extends Applet { StringBuffer buf; String FileToRead="message.txt"; TextArea ta; //---------------------------------------------------------------- public void init() { ta = new TextArea(40, 40); ta.setEditable(false); setLayout(new BorderLayout()); add(ta, "Center"); // Get setup parameters from applet html String param = getParameter("FileToRead"); if ( param != null){ FileToRead = new String(param); } // Now read the file. readFile(); } //---------------------------------------------------------------- public void readFile(){ String line; URL url=null; try { url = new URL (getCodeBase(), FileToRead ); } catch (MalformedURLException e ) { System.out.println("Malformed URL "); stop(); } try { InputStream in=url.openStream(); BufferedReader dis = new BufferedReader(new InputStreamReader(in)); buf = new StringBuffer () ; while ((line = dis.readLine()) != null){ buf.append(line + "\n"); } in.close(); } catch (IOException e ) {} // Load the file into the TextArea. ta.append(buf.toString ()); } }