jeremytaffy
Technical User
I am using java 1.3 on AIX 5.1. This doesnt work. It gives me errors about having catch with no try?????
import java.awt.*;
import java.io.*;
public class FileViewer extends Frame {
Button close;
// Query the size of the specified file, create an array of bytes big
// enough, and read it in. Then create a TextArea to display the text
// and a "Close" button to pop the window down.
public FileViewer(String filename) throws IOException {
super("FileViewer: " + filename);
File f = new File(filename);
int size = (int) f.length();
int bytes_read = 0;
FileInputStream in = new FileInputStream(f);
byte[] data = new byte[size];
while(bytes_read < size)
bytes_read += in.read(data, bytes_read, size-bytes_read);
TextArea textarea = new TextArea(new String(data, 0), 24, 80);
textarea.setFont(new Font("Helvetica", Font.PLAIN, 12));
textarea.setEditable(false);
this.add("Center", textarea);
close = new Button("Close"
this.add("South", close);
this.pack();
this.show();
}
// Handle the close button by popping this window down
public boolean action(Event e, Object what) {
if (e.target == close) {
this.hide();
this.dispose();
return true;
}
return false;
}
// The FileViewer can be used by other classes, or it can be
// used standalone with this main() method.
static public void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Usage: java FileViewer <filename>"
System.exit(0);
}
// try {
// Frame f = new FileViewer(args[0]);
// catch (IOException e) System.out.println(e);
// }
}
}
with errors:
FileViewer.java:54: 'catch' without 'try'
catch (IOException e) System.out.println(e);
^
FileViewer.java:52: 'try' without 'catch' or 'finally'
try {
^
Note: FileViewer.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
2 errors
import java.awt.*;
import java.io.*;
public class FileViewer extends Frame {
Button close;
// Query the size of the specified file, create an array of bytes big
// enough, and read it in. Then create a TextArea to display the text
// and a "Close" button to pop the window down.
public FileViewer(String filename) throws IOException {
super("FileViewer: " + filename);
File f = new File(filename);
int size = (int) f.length();
int bytes_read = 0;
FileInputStream in = new FileInputStream(f);
byte[] data = new byte[size];
while(bytes_read < size)
bytes_read += in.read(data, bytes_read, size-bytes_read);
TextArea textarea = new TextArea(new String(data, 0), 24, 80);
textarea.setFont(new Font("Helvetica", Font.PLAIN, 12));
textarea.setEditable(false);
this.add("Center", textarea);
close = new Button("Close"
this.add("South", close);
this.pack();
this.show();
}
// Handle the close button by popping this window down
public boolean action(Event e, Object what) {
if (e.target == close) {
this.hide();
this.dispose();
return true;
}
return false;
}
// The FileViewer can be used by other classes, or it can be
// used standalone with this main() method.
static public void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Usage: java FileViewer <filename>"
System.exit(0);
}
// try {
// Frame f = new FileViewer(args[0]);
// catch (IOException e) System.out.println(e);
// }
}
}
with errors:
FileViewer.java:54: 'catch' without 'try'
catch (IOException e) System.out.println(e);
^
FileViewer.java:52: 'try' without 'catch' or 'finally'
try {
^
Note: FileViewer.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
2 errors