forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestWrite.java
More file actions
38 lines (33 loc) · 903 Bytes
/
Copy pathTestWrite.java
File metadata and controls
38 lines (33 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class TestWrite extends JApplet
implements ActionListener
{
JTextArea ta = new JTextArea();
public void init() {
JButton button = new JButton("Test Write");
button.addActionListener( this );
JPanel p = new JPanel();
p.add( button );
getContentPane().add( "North", p );
getContentPane().add( "Center", new JScrollPane(ta) );
}
public void actionPerformed( ActionEvent e )
{
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...");
}
}
private void write( String s ) {
ta.append( s + "\n" );
}
}