1 23 24 package org.cofax.util; 25 26 import java.net.*; 27 import java.io.*; 28 29 public class UrlGetter { 30 31 private static URL address; 32 33 private static String localname; 34 35 private static StringBuffer page; 36 37 public static StringBuffer getpage(URL address) { 38 39 StringBuffer textIn = new StringBuffer (16384); 40 41 try { 42 BufferedReader in = new BufferedReader(new InputStreamReader(address.openStream())); 43 44 String inputLine; 45 46 while ((inputLine = in.readLine()) != null) 47 textIn.append(inputLine); 48 in.close(); 49 } 50 51 catch (IOException e) { 52 System.err.println("Caught IOException: " + e.getMessage()); 53 } 54 55 return textIn; 56 } 57 58 public static void printpage(StringBuffer contents, String localname) { 59 60 try { 61 FileOutputStream out; PrintStream p; out = new FileOutputStream(localname); 64 65 p = new PrintStream(out); p.println(contents); 68 } 69 70 catch (FileNotFoundException e) { 71 System.err.println("Caught Exception: " + e.getMessage()); 72 } 73 74 } 75 76 public static void main(String [] args) throws Exception { 77 78 address = new URL(args[0]); 79 localname = args[1]; 80 81 page = UrlGetter.getpage(address); 82 UrlGetter.printpage(page, localname); 83 84 } 85 86 } 87 | Popular Tags |