KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > FileView


1 /*
2  * @(#)FileView.java 1.5 99/12/06
3  *
4  * Copyright 1997-1999 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * This software is the proprietary information of Sun Microsystems, Inc.
7  * Use is subject to license terms.
8  *
9  */

10
11 import java.awt.*;
12 import java.beans.*;
13 import java.net.*;
14 import javax.activation.*;
15
16 public class FileView {
17     private Frame frame;
18
19     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
20         FileView fv = new FileView();
21         if (args.length == 0) {
22             System.out.println("usage: FileView file.txt");
23             System.exit(1);
24         }
25         fv.view(args[0]);
26     }
27
28     private void view(String JavaDoc filename) throws Exception JavaDoc {
29     FileDataSource fds = new FileDataSource(filename);
30     DataHandler dh = new DataHandler(fds);
31     // comment out previous two lines, and uncomment next
32
// line and pass in a URL on the command line.
33
// DataHandler dh = new DataHandler(new URL(filename));
34

35     CommandInfo bi = dh.getCommand("view");
36     
37     if (bi == null) {
38         System.out.println("no viewer found, exiting");
39         System.exit(1);
40     }
41
42     frame = new Frame("Viewer");
43     frame.add((Component)dh.getBean(bi));
44     frame.setSize(new Dimension(400,300));
45     frame.show();
46     }
47 }
48
Popular Tags