/** * By default, this applet raises a security exception. * * With JDK 1.1 appletviewer, * if you configure your system to allow applets signed by "Duke" * to run on your system, then this applet can run and write a file * to your /tmp directory. (or to the file named "tmpfoo" on a * Windows system) * * @version JDK 1.1 * @author Marianne Mueller */ import java.awt.*; import java.io.*; import java.lang.*; import java.applet.*; public class writeFile extends Applet { String myFile = "/tmp/foo"; File f = new File(myFile); DataOutputStream dos; public void init() { String osname = System.getProperty("os.name"); if (osname.indexOf("Windows") != -1) { myFile="tmpfoo"; } } public void paint(Graphics g) { try { dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile),128)); dos.writeChars("Cats can hypnotize you when you least expect it\n"); dos.flush(); g.drawString("Successfully wrote to the file named " + myFile + " -- go take a look at it!", 10, 10); String name = System.getProperty("user.name"); g.drawString("And, successfully got user.name ..." + name, 10, 30); } catch (SecurityException e) { g.drawString("writeFile: caught security exception", 10, 10); } catch (IOException ioe) { g.drawString("writeFile: caught i/o exception", 10, 10); } } }