Create and write a file test.txt in the current directory. However, this applet cannot create a file unless it is explicitly granted permissions in the policy file.
Import java. AWT .*;
Import java. Io .*;
Import java. Lang .*;
Import java. Applet .*;
Public class appletwritertest extends applet {
File F = new file ("test.txt ");
Dataoutputstream DOS;
Public void Init (){
System. Out. println ("appletwritefiletest Init ;");
}
Public void paint (Graphics g ){
Try {
// Line a local file
DOS = new dataoutputstream (New bufferedoutputstream (New fileoutputstream (F )));
Dos. writechars ("Hello, this is something test !!! ");
Dos. Flush ();
// If the message is displayed successfully
G. drawstring ("test successfully !!!! ", 10, 10 );
}
Catch (securityexception e ){
// Output exception Stack
E. printstacktrace ();
G. drawstring ("security exception:" + e, 10, 10 );
}
Catch (ioexception IOE ){
G. drawstring ("I/O exception", 10, 10 );
}
}
}