FileDocCategorySizeDatePackage
TestWrite.javaAPI DocExample813Thu Jun 05 23:06:18 BST 1997None

TestWrite.java

import java.awt.*;
import java.applet.*;
import java.io.*;

public class TestWrite extends Applet {
	TextArea ta = new TextArea();

	public void init() {
		setLayout( new BorderLayout() );
		Panel p = new Panel();
		p.add( new Button("Test Write") );
		add( "North", p );
		add( "Center", ta );
	}

	public boolean action ( Event e, Object arg ) {
		try {
			String fname = "." + File.separator + "testwrite.xxx";
			write("Attempting to write file: "+fname);
			FileOutputStream file = new FileOutputStream(fname);
			new PrintStream( file ).println("Hello...");
			file.close();
			write("Success!");
		} catch ( Exception e2 ) {
			write( "Caught Exception: " + e2 );
			write("Failed to write file...");
		}
		return true;
	}

	private void write( String s ) {
		ta.setText( ta.getText() + s + "\n" );
	}
}