Download this source file
/*
*/
// Writefile - Creates a file called "WriteTst.txt" in the current directory.
// By default, this will cause a security exception, unless
// you configure your policy to allow applets from its location
// to write to the file "WriteTst.txt".
//
// Written by Wayne Pollock, Tampa Florida USA, 3/2000.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class WriteFile extends Applet
{
String myFile = "/Temp/WriteTst.txt";
File f = new File( myFile );
DataOutputStream dos;
public void paint ( Graphics g )
{
g.setFont( new Font( "Serif", Font.BOLD, 14 ) );
try
{ dos = new DataOutputStream(
new BufferedOutputStream( new FileOutputStream( myFile ),128 ) );
dos.writeBytes( "A man, A Plan, A Canal...Panama!\r\n" );
dos.flush();
g.drawString( "Created the file \"" + myFile + "\"!", 10, 15 );
}
catch ( SecurityException se )
{ g.drawString( "Security exception in WriteFile Applet: ", 10, 15 );
g.drawString( "" + se, 10, 34 );
}
catch ( IOException ie )
{ g.drawString( "I/O exception in WriteFile Applet:", 10, 15 );
g.drawString( "" + ie, 10, 34 );
}
}
public static void main ( String [] args )
{
WriteFile wf = new WriteFile();
Frame f = new Frame( "WriteFile" );
f.addWindowListener( new WindowAdapter()
{ public void windowClosing ( WindowEvent we )
{ System.exit( 0 );
}
}
);
f.setSize( 650, 80 );
f.add( wf );
wf.init();
wf.start();
f.setVisible( true );
}
}