1 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 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 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 e) { 57 e.printStackTrace(); 58 } 59 60 61 } 62 63 64 } 65 | Popular Tags |