import java.io.*; import java.net.*; /** * Read from a file given as a URL. Throw a nasty exception in any problem * happens when manipulating the URL. */ public class InputURL { // the url of the file to read from private URL url; // the stream used to read from the file private BufferedReader in; public InputURL(String URLName) { // URL of the file try{ url = new URL(URLName); } catch(MalformedURLException me){ me.printStackTrace(); throw new Error("Can't create URL"); } // Create an input stream from the file try{ in = new BufferedReader( new InputStreamReader(url.openStream())); } catch(IOException ioe){ ioe.printStackTrace(); throw new Error("Can't open a stream from the file"); } } /** * Close the input stream when done with this InputURL */ public void finalize() { try{ in.close(); } catch(IOException ioe){ ioe.printStackTrace(); throw new Error("Error while closing the file"); } } /** * Read a line from the file */ public String readLine() { try{ return in.readLine(); } catch(IOException ioe){ ioe.printStackTrace(); throw new Error("Error while reading from the file"); } } }