1 50 51 package org.openlaszlo.iv.flash; 52 53 import java.io.*; 54 import java.util.*; 55 import java.net.*; 56 57 59 public final class GetUrl { 60 61 public static void help() { 62 System.err.println( "Get url v1.0" ); 63 System.err.println( "Copyright (c) Dmitry Skavish, 2000. All rights reserved." ); 64 System.err.println( "" ); 65 System.err.println( "Usage: geturl <url> <filename>" ); 66 System.err.println( "" ); 67 System.exit(1); 68 } 69 70 public static void err( String msg ) { 71 System.err.println( msg ); 72 help(); 73 } 74 75 public static void main( String [] args ) throws MalformedURLException { 76 77 String surl = args[0]; 78 String filename = args[1]; 79 80 try { 81 URL url = new URL( surl ); 82 byte[] buffer = new byte[4096*4]; 83 84 OutputStream out = new FileOutputStream( filename ); 85 URLConnection conn = url.openConnection(); 86 conn.connect(); 87 InputStream is = conn.getInputStream(); 88 int size; 89 while( (size=is.read(buffer, 0, buffer.length))>0 ) { 90 out.write(buffer, 0, size); 91 } 92 is.close(); 93 out.close(); 94 95 System.out.println( "url.getRef():"+url.getRef() ); 96 } catch( Exception e ) { 97 err( e.getMessage() ); 98 } 99 } 100 } 101 | Popular Tags |