FileDocCategorySizeDatePackage
FileViewer.javaAPI DocExample2098Sat Jun 02 03:11:32 BST 2001None

FileViewer

public class FileViewer extends Frame

Fields Summary
Button
close
Constructors Summary
public FileViewer(String filename)

        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();
    
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object what)

        if (e.target == close) {
            this.hide();
            this.dispose();
            return true;
        }
        return false;
    
public static voidmain(java.lang.String[] args)

        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); }