/** * With Netscape Navigator 2.0, this always raises security exception. * * With JDK 1.0 appletviewer, * for applets loaded over the net, if acl.read=/etc, then this works. * * if you install this applet's .class file in a directory on your * CLASSPATH, then the applet can read files on the client file * system, regardless of how you set acl.read. * * @version JDK 1.0 beta * @author Marianne Mueller */ import java.awt.*; import java.io.*; import java.lang.*; import java.applet.*; public class readFile extends Applet { String myFile = "/etc/passwd"; String firstLine; public void testRead(Graphics g) throws IOException { SecurityException se = null; File f = new File(myFile); DataInputStream dis; if (f.exists()) try { dis = new DataInputStream(new BufferedInputStream(new FileInputStream(myFile),128)); firstLine = "First line is: " + dis.readLine(); } catch (IOException ioe) { System.out.println("testRead: caught IO exception"); throw ioe; } catch (SecurityException e) { se = e; throw e; } else firstLine = "but " + myFile + " doesn't exist"; } public void paint(Graphics g) { try { testRead(g); g.drawString("Successful attempt to access " + myFile, 10, 10); g.drawString(firstLine, 10, 30); } catch (SecurityException e) { g.drawString("readFile: caught security exception", 10, 10); } catch (IOException ioe) { g.drawString("paint: caught i/o exception", 10, 10); } } }