KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DHURL


1 /*
2  * @(#)DHURL.java 1.3 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.net.*;
12 import java.io.*;
13 import javax.activation.*;
14
15 public class DHURL {
16     URL url = null;
17     DataHandler dh = null;
18     
19     public static void main(String JavaDoc args[]){
20         DHURL test = new DHURL();
21
22         if(args.length == 0) {
23             System.out.println("usage: DHURL url");
24             System.exit(1);
25         }
26
27         test.setURL(args[0]);
28
29         test.doit();
30
31     }
32
33     public void setURL(String JavaDoc url) {
34     
35     try {
36         this.url = new URL(url);
37     } catch(MalformedURLException e) {
38         e.printStackTrace();
39         System.out.println("malformed URL!!!");
40         System.exit(1);
41     }
42
43     }
44     
45     public void doit() {
46     System.out.print("Creating DataHandler...");
47     dh = new DataHandler(url);
48     System.out.println("...done.");
49
50     System.out.println("The MimeType of the DH : " +
51                dh.getContentType());
52     try {
53     InputStream is = dh.getInputStream();
54     if(is != null)
55         System.out.println("got an inputstream");
56     } catch(Exception JavaDoc e) {
57         e.printStackTrace();
58     }
59
60     
61     }
62     
63     
64 }
65
Popular Tags